I am using rspec/capybara/VCR to record tapes. Currently my tapes are automatically named to include a simplified version of the hierarchy of the test that is being run, as is the default.
I would like to configure the cassette naming scheme so that it is dependent instead on the parameters of the request, so any PUT to /abc.com with a body of XYZ would use the same tape. My thought was to configure VCR with this:
config.around_http_request do |request|
tape_name = Digest::SHA1.hexdigest [request.method, request.uri, request.headers.to_s, request.body.to_s].join('')
puts "Using tape #{tape_name}"
puts "on = #{VCR.turned_on?}"
VCR.use_cassette(tape_name, :record => :new_episodes, &request)
end
But when I do that, eventually I get the errors such as:
There is already a cassette with the same name (5d971f35322c4e0cf7d379aa39a28ef12994552f). You cannot nest multiple cassettes with the same name.
How can I name tapes with what they contain and prevent this error?