Created
October 24, 2012 06:52
-
-
Save myronmarston/3944450 to your computer and use it in GitHub Desktop.
VCR custom matcher example
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 |vcr| | |
normalized_uri = lambda do |uri| | |
uri = URI(uri) | |
path_parts = uri.path.split('/') | |
# put a deterministic value in place of the non-deterministic username | |
path_parts[2] = '__username__' | |
uri.path = path_parts.join('/') | |
uri.to_s | |
end | |
uri_start = 'https://172.31.56.92/users' | |
vcr.register_request_matcher :uri_ignoring_username do |req_1, req_2| | |
if req_1.uri.start_with?(uri_start) && req_2.uri.start_with?(uri_start) | |
normalized_uri[req_1.uri] == normalized_uri[req_2.uri] | |
else | |
# match on the full URI for other requests... | |
req_1.uri == req_2.uri | |
end | |
end | |
vcr.default_cassette_options = { :match_requests_on => [:method, :uri_ignoring_username] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment