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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.