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 the specs scope as the cassette name when the description is empty #514

Merged
merged 1 commit into from Nov 16, 2015
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
7 changes: 6 additions & 1 deletion lib/vcr/test_frameworks/rspec.rb
Expand Up @@ -8,7 +8,12 @@ module Metadata
def configure!
::RSpec.configure do |config|
vcr_cassette_name_for = lambda do |metadata|
description = metadata[:description]
description = if metadata[:description].empty?
# we have an "it { is_expected.to be something }" block
metadata[:scoped_id]
else
metadata[:description]
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure the state of things is that metadata[:description] will either be a full string "something" or an empty string ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the case while I had my debugger in that line. I can play save and add a nil-check, though :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best, unless we can be better up the line and add a place that does metadata[:description] = ... || ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this method in the rspec core, the description can never be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krainboltgreene is that info what you needed? Or shall I add a nil check?

example_group = if metadata.key?(:example_group)
metadata[:example_group]
else
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/vcr/test_frameworks/rspec_spec.rb
Expand Up @@ -17,6 +17,17 @@
])
end
end

context 'when the spec has no description' do
it do
expect(VCR.current_cassette.name.split('/')).to eq([
'VCR::RSpec::Metadata',
'an example group',
'when the spec has no description',
'1:1:2:1'
])
end
end
end

context 'with the cassette name overridden at the example group level', :vcr => { :cassette_name => 'foo' } do
Expand Down