0

i have to extend an exsiting cucumber feature with some new scenarios covering some new behaviour. At the moment this whole cucumber/vcr thingy is set up as such that it will look for cassettes with matching scenario name:

feature bar

  @vcr
  scenario foo

will look for a recorded cassette in ./cassettes/bar/foo.yml. But there are further scenarios which could recycle the before recorded cassette. (The ones to add from my side too). So there is a folder bloated with the same cassette for each scenario but only renamed:

feature bar

  @vcr
  scenario foo

  @vcr
  scenario foo1

  ...

  @vcr
  scenario fooX

So were is ./cassettes/bar/foo.yml, ./cassettes/bar/foo1.yml ... ./cassettes/bar/fooX.yml with exact same content. What is the proper way to get this dry?

Is there a possibility to specify the vcr cassette to be used explicitly, something like?

  @vcr(:cassette => foo)
  scenario fooX

many thanks ;)

jethroo
  • 2,086
  • 2
  • 18
  • 30

1 Answers1

0

I solved this issue by defining a new tag for VCR:

#./test_helper/vcr.rb
VCR.cucumber_tags do |t|
  t.tag '@vcr', use_scenario_name: true
  t.tag '@foo'
end

And then i added a before and after hook, which loads my wanted cassette:

# ./features/support/env.rb
Before('@foo') do
  VCR.insert_cassette('cassettes/bar/foo')
end

After('@foo') do
  VCR.eject_cassette
end

So now i simply needed to annotate my new defined tag for the similar scenarios:

feature bar

  @foo
  scenario foo

  @foo
  scenario foo1

  ...

  @foo
  scenario fooX

So now i only have one recorded cassette file left.

jethroo
  • 2,086
  • 2
  • 18
  • 30
  • `VCR.cucumber_tags { |t| t.tag '@foo' }` sets up the `Before`/`After` hooks for you. That's literally what it does, and why it exists, so there's no need to setup the hooks yourself. Alternately, if you want to do it yourself, that's fine -- but I would remove the `tag @foo` declaration as it's not doing anything. – Myron Marston Feb 04 '14 at 20:02
  • Sorry i'm a bit puzzled now i did exactly what you proposed yourself in https://github.com/vcr/vcr/issues/130, if i want to use a specific casette i should specify it in the hooks so i did. – jethroo Feb 04 '14 at 22:35
  • If you want to use a specific cassette, and you don't want it to be auto-named based on the cucumber tag, then yes: you need to use the hooks and do it yourself. But in that case, there's no need to declare `t.tag '@foo'` as you are manually doing what `t.tag` usually does for you. OTOH, if you don't care to specify the full cassette name and simply want to reuse a cassette for multiple scenarios and are happy to let VCR organize it for you into a cucumber_tags directory based on the tag name, then you can use `t.tag` w/o declaring the hooks yourself. – Myron Marston Feb 05 '14 at 23:37