Skip to content

Instantly share code, notes, and snippets.

@gaffneyc
Created November 19, 2015 16:15
Show Gist options
  • Save gaffneyc/3ed183042e3b9a90fab9 to your computer and use it in GitHub Desktop.
Save gaffneyc/3ed183042e3b9a90fab9 to your computer and use it in GitHub Desktop.
VCR matcher for forms
VCR.configure do |c|
# Match the content of urlencoded forms instead of their encoded version.
# This is to address issues with different ordering of the same information.
c.register_request_matcher :form do |actual, match|
content_type = actual.headers["Content-Type"]
# Only valid for forms
if content_type.include?("application/x-www-form-urlencoded")
actual_form = Rack::Utils.parse_nested_query(actual.body)
match_form = Rack::Utils.parse_nested_query(match.body)
actual_form == match_form
else
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment