tags, vcr, and cassette names

109 views
Skip to first unread message

Donald Plummer

unread,
Sep 11, 2013, 1:48:57 PM9/11/13
to ruby-...@googlegroups.com
I'm trying to setup VCR to record any scenarios which are tagged with "@vcr". Since turnip just turns tags into rspec metadata, this almost works. Unfortunately, the cassette_name that VCR generates is too long, since it is the name of the scenario plus all the steps. How can I specify the format of the cassette name?

Thanks,
Donald

Donald Plummer

unread,
Sep 11, 2013, 3:43:26 PM9/11/13
to ruby-...@googlegroups.com
I've dug into VCR and I'd say its completely a problem on that end. The solution I came up with was adding the "@turnip_vcr" tag and specifying this around block, after the VCR.configure {|c| c.configure_rspec_metadata!} (which is where the vcr_cassette_name_for lambda is defined.

config.around(:each, :turnip_vcr) do |example|
  cassette_name = vcr_cassette_name_for[example.metadata[:example_group]]
  VCR.use_cassette(cassette_name, {}, &example)
end

This creates a cassette named "#{Feature name}/#{Scenario name}".

Cheers!
Donald

Donald Plummer

unread,
Sep 11, 2013, 4:20:46 PM9/11/13
to ruby-...@googlegroups.com
I spoke too soon, that lambda isn't available. This is what is actually working:

RSpec.configure do |config|
  config.around(:each, :turnip_vcr => ->(v){!!v}) do |example|
    cassette_name = [example.metadata[:example_group][:example_group][:description],
      example.metadata[:example_group][:description],
    ].join('/')
    VCR.use_cassette(cassette_name, {}, &example)
  end
end
Reply all
Reply to author
Forward
0 new messages