I am using VCR to record http interactions with an external API. This is my (working) code:
it 'does xyz....' do
hook_payload = {ruby_hash: 'here'}
VCR.use_cassette('my_folder/create_project') do
VCR.use_cassette('my_folder/get_project') do
update = Update.new(hook_payload)
expect { update.call }.to change { Projects.count }.by(1)
end
end
end
The code above works, but the organization isn't good, as I prefer to have the expect{}
call outside the block. So, I tried this, but the following code does not work:
context 'my context', vcr: { group: 'my_folder', cassettes: %w[create_project get_project] } do
it 'does xyz....' do
hook_payload = {ruby_hash: 'here'}
update = Update.new(hook_payload)
expect { update.call }.to change { Projects.count }.by(1)
end
However this code doesn't work and I get the following error:
VCR is currently using the following cassette: - /Users/me/this_project/spec/fixtures/vcr/my_folder/create_project.yml.
Under the current configuration VCR can not find a suitable HTTP interaction to replay and is prevented from recording new requests.
I am 100% sure that my_folder/get_project.yml
is valid, and it works in other tests in the project.
I even put the cassettes (%w[create_project get_project]
) in the same order that they are used in my code. What am I doing incorrectly here?