Testing with the VCR Gem

There’s one more step to cover while we are still talking about this payment example: testing—specifically, testing our interaction with third-party services. Testing third-party services is hard because they are traditionally located across the network from our little tests, making them slow to access in a unit test situation, and also fragile and hard to run on, say, a train with no Wi-Fi.

The VCR[18] gem makes testing third-party services much easier. The gem monitors the interaction between your test and the rest of the world. If your test makes an HTTP request, VCR intercepts the responses and saves them as a “cassette,” which is just a YAML file with a particular structure. The next time you run the test, VCR intercepts ...

Get Take My Money 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.