Created
November 19, 2015 16:15
-
-
Save gaffneyc/3ed183042e3b9a90fab9 to your computer and use it in GitHub Desktop.
VCR matcher for forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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