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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access