Skip to content

Instantly share code, notes, and snippets.

@MelissaKaulfuss
Last active March 21, 2018 10:14
Show Gist options
  • Save MelissaKaulfuss/2efc0b6419f4ecbf4c3a12421f00905b to your computer and use it in GitHub Desktop.
Save MelissaKaulfuss/2efc0b6419f4ecbf4c3a12421f00905b to your computer and use it in GitHub Desktop.
VCR gem grappling and learnings.

Today I had to add a parameter to a request we were sending to an external API.

My unit test passed ✅ The acceptance specs did not - I had 20 failures. ❌

The failures were super cryptic, something about not being able to merge Nil:NilClass into a hash or something weirdly unrelated. One of my colleagues suspected it was to do with the VCR gem we used to simulate HTTP requests/responses from APIs.

Turns out VCR uses query strings as the key for the cassette (I did not know this). Because I'd added a param to the query string, the existing string (in the cassettes) was broken. Turns out passing different values or params will make new request rather than using the recorded responses and so the request was trying to be sent out rather than using the cassette. So we needed to re-record the cassettes.

I tried to get them to record again a few different ways to no avail. Ended up simply editing the URI string and adding the new param (remember these are included in alphabetical order!). And, low and behold, green tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment