我正在使用VCR记录与外部API的http交互。这是我的(有效的)代码:
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
上面的代码有效,但是组织不好,因为我更喜欢在块外进行expect{}
调用。因此,我尝试了此操作,但是以下代码不起作用:
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
但是此代码不起作用,并且出现以下错误:
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.
我100%确定my_folder/get_project.yml
有效,并且可以在项目中的其他测试中使用。
我什至以与我的代码中使用的顺序相同的顺序放置卡带(%w[create_project get_project]
)。我在这里做错了什么?