Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created October 24, 2012 06:52
Show Gist options
  • Save myronmarston/3944450 to your computer and use it in GitHub Desktop.
Save myronmarston/3944450 to your computer and use it in GitHub Desktop.
VCR custom matcher example
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