Configure how VCR matches requests to recorded cassettes

VCR lets you configure how it matches requests to recorded cassettes Show archive.org snapshot :

In order to properly replay previously recorded requests, VCR must match new
HTTP requests to a previously recorded one. By default, it matches on HTTP
method and URI, since that is usually deterministic and fully identifies the
resource and action for typical RESTful APIs.

You can customize how VCR matches requests using the :match_requests_on cassette option.

There are number of predefined matching options like :uri or :path.

You can also go nuclear and provide a lambda to match requests and cassettes. Here is an example from the VCR docs that match requests by method and port:

port_matcher = lambda do |request_1, request_2|
  URI(request_1.uri).port == URI(request_2.uri).port
end

VCR.use_cassette('example', :match_requests_on => [:method, port_matcher]) do
  puts "Response for port 8000: " + response_body_for(:get, "http://example.com:8000/")
end
Henning Koch