Reputation: 4215
On all specs with requests to example.com
I want to ignore the trailing id in the URI with respect the request matcher. Something like this.
VCR.configure do |c|
# omitted
c.register_request_matcher :uri_ignoring_trailing_id do |request_1, request_2|
# omitted
end
c.before_http_request(lambda { |req| req.uri =~ /example.com/ }) do
c.default_cassette_options = { match_requests_on: [ :uri_ignoring_trailing_id ] }
end
end
Upvotes: 3
Views: 659
Reputation: 21810
Modifying the global configuration in before_http_request
is a bad idea because it'll affect every request made after you change the config, not just the ones matching example.com
. Here's how I would recommend you do this instead:
VCR.configure do |vcr|
uri_matcher = VCR.request_matchers[:uri]
vcr.register_request_matcher(:uri_ignoring_trailing_id_for_example_dot_com) do |req_1, req_2|
if req_1.parsed_uri.host == "example.com" && req_2.parsed_uri.host == "example.com"
# do your custom matching where you ignore trailing id
else
uri_matcher.matches?(req_1, req_2)
end
end
vcr.default_cassette_options = { match_requests_on: [:method, :uri_ignoring_trailing_id_for_example_dot_com] }
end
Upvotes: 7