Using VCR for mock requests

VCR is a popular tool for recording and replaying HTTP requests. VCR was created by Myron Marston, who also happens to be the lead developer of RSpec. Although it is much more sophisticated than our primitive HTTP request mocking setup, at its heart, VCR works the same way: it records real HTTP requests to files and replays them during specs. The nice thing about VCR is that it does everything in a configurable and automated way. We can tap into recorded HTTP requests with a small configuration file and an RSpec tag, so we don't actually have much code in our specs related to mocking HTTP requests. We can also record new HTTP requests very easily to a new cassette (the term used by VCR for the file that records the ...

Get RSpec Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.