Skip to content

Instantly share code, notes, and snippets.

@danlucraft
Created July 10, 2013 11:31
Show Gist options
  • Save danlucraft/5965531 to your computer and use it in GitHub Desktop.
Save danlucraft/5965531 to your computer and use it in GitHub Desktop.
How to make VCR not fail to match the request body because the JSON hashes have been serialised in a different order
VCR.configure do |v|
v.register_request_matcher :json_aware_body do |r1, r2|
r1.body == r2.body || (
r1.headers["Content-Type"].inspect =~ /json/ and JSON.parse(r1.body) == JSON.parse(r2.body))
end
end
VCR.use_cassette('example', :match_requests_on => [:json_aware_body]) do
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment