Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RSpec metadata value as cassette name if value is String #774

Merged
merged 2 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/vcr/test_frameworks/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ def configure!
config.before(:each, when_tagged_with_vcr) do |ex|
example = ex.respond_to?(:metadata) ? ex : ex.example

cassette_name = nil
options = example.metadata[:vcr]
options = options.is_a?(Hash) ? options.dup : {} # in case it's just :vcr => true

cassette_name = options.delete(:cassette_name) ||
options = case options
when Hash #=> vcr: { cassette_name: 'foo' }
options.dup
when String #=> vcr: 'bar'
cassette_name = options.dup
{}
else #=> :vcr or vcr: true
{}
end

cassette_name ||= options.delete(:cassette_name) ||
vcr_cassette_name_for[example.metadata]
VCR.insert_cassette(cassette_name, options)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/vcr/test_frameworks/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
end
end

context 'when the metadata value is a string', vcr: 'foo' do
it 'uses that string as the cassette name' do
expect(VCR.current_cassette.name).to eq('foo')
end

context 'when defined on the example level' do
it 'uses that string as the cassette name', vcr: 'bar' do
expect(VCR.current_cassette.name).to eq('bar')
end
end
end

it 'allows the cassette name to be overriden', :vcr => { :cassette_name => 'foo' } do
expect(VCR.current_cassette.name).to eq('foo')
end
Expand Down