Using VCR to Mock Your Requests

In the past months, I’ve been working with a lot of external API requests. Since I’m part of the Marley Spoon’s logistics team, our challenge is to make sure our requests are done in time and everything is delivered in good shape.

Part of this task, as a software developer, is making sure the code I write is well tested, and does what it is supposed to do. Our software has many integrations with our logistics partners. When integrating with their systems, we don’t want to hit external APIs with real requests every time we run our tests. This not only generates unnecessary requests that can cause problems with API rate limits and other unwanted side-effects. It also makes them run slower. To avoid that, we pretend to make real requests and there is a tool that helps “faking” these calls: by recording real data from a real network request, we are able to stub a third party’s web service response. The saved data is called a “cassette tape” and the name of the tool I refer to is VCR.

[Read More]