Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use separate Before/After hooks rather than a single Around hook.

Unfortunately, cucumber doesn't run background steps within the Around hook.

Closes #45.
  • Loading branch information...
commit acfb274a6fdf8d6ba6e2f1e842a9269a1d11a6c5 1 parent fd67425
@myronmarston authored
View
3  CHANGELOG.md
@@ -21,6 +21,9 @@
* Add support for running tests through `gem test vcr`. Visit
[test.rubygems.org](http://test.rubygems.org/gems/vcr) to see
the results.
+* Fix cucumber support to use separate `Before` & `After` hooks rather than
+ a single `Around` hook because of a bug in cucumber that prevents
+ background steps from running within the `Around` hook.
## 1.6.0 (February 3, 2011)
View
12 lib/vcr/test_frameworks/cucumber.rb
@@ -21,8 +21,16 @@ def tags(*tag_names)
tag_name = "@#{tag_name}" unless tag_name =~ /^@/
cassette_name = "cucumber_tags/#{tag_name.gsub(/\A@/, '')}"
- @main_object.Around(tag_name) do |scenario, block|
- VCR.use_cassette(cassette_name, options, &block)
+ # It would be nice to use an Around hook here, but
+ # cucumber has a bug: background steps do not run
+ # within an around hook.
+ # https://gist.github.com/652968
+ @main_object.Before(tag_name) do
+ VCR.insert_cassette(cassette_name, options)
+ end
+
+ @main_object.After(tag_name) do
+ VCR.eject_cassette
end
self.class.add_tag(tag_name)
View
20 spec/vcr/test_frameworks/cucumber_spec.rb
@@ -2,20 +2,24 @@
describe VCR::CucumberTags do
subject { described_class.new(self) }
- let(:blocks_for_tags) { {} }
+ let(:before_blocks_for_tags) { {} }
+ let(:after_blocks_for_tags) { {} }
- # define our own Around so we can test this in isolation from cucumber's implementation.
- def Around(tag, &block)
- blocks_for_tags[tag.sub('@', '')] = block
+ # define our own Before/After so we can test this in isolation from cucumber's implementation.
+ def Before(tag, &block)
+ before_blocks_for_tags[tag.sub('@', '')] = block
+ end
+
+ def After(tag, &block)
+ after_blocks_for_tags[tag.sub('@', '')] = block
end
def test_tag(cassette_attribute, tag, expected_value)
VCR.current_cassette.should be_nil
- cassette_during_scenario = nil
- scenario = lambda { cassette_during_scenario = VCR.current_cassette }
- blocks_for_tags[tag].call(:scenario_name, scenario)
- cassette_during_scenario.send(cassette_attribute).should == expected_value
+ before_blocks_for_tags[tag].call
+ VCR.current_cassette.send(cassette_attribute).should == expected_value
+ after_blocks_for_tags[tag].call
VCR.current_cassette.should be_nil
end
Please sign in to comment.
Something went wrong with that request. Please try again.