Class: VCR::CucumberTags
- Inherits:
-
Object
- Object
- VCR::CucumberTags
- Defined in:
- lib/vcr/test_frameworks/cucumber.rb
Overview
Provides integration with Cucumber using tags.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(main_object) ⇒ CucumberTags
constructor
A new instance of CucumberTags.
-
#tags(*tag_names) ⇒ Object
(also: #tag)
Adds ‘Before` and `After` cucumber hooks for the named tags that will cause a VCR cassette to be used for scenarios with matching tags.
Constructor Details
#initialize(main_object) ⇒ CucumberTags
Returns a new instance of CucumberTags.
19 20 21 |
# File 'lib/vcr/test_frameworks/cucumber.rb', line 19 def initialize(main_object) @main_object = main_object end |
Class Method Details
.add_tag(tag) ⇒ Object
11 12 13 |
# File 'lib/vcr/test_frameworks/cucumber.rb', line 11 def add_tag(tag) << tag end |
.tags ⇒ Object
6 7 8 |
# File 'lib/vcr/test_frameworks/cucumber.rb', line 6 def .dup end |
Instance Method Details
#tags(*tag_names) ⇒ Object Also known as: tag
Adds ‘Before` and `After` cucumber hooks for the named tags that will cause a VCR cassette to be used for scenarios with matching tags.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vcr/test_frameworks/cucumber.rb', line 30 def (*tag_names) = tag_names.last.is_a?(::Hash) ? tag_names.pop : {} tag_names.each do |tag_name| tag_name = "@#{tag_name}" unless tag_name =~ /\A@/ # 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 |scenario| = .dup cassette_name = if .delete(:use_scenario_name) feature = scenario.respond_to?(:scenario_outline) ? scenario.scenario_outline.feature : scenario.feature name = feature.name.split("\n").first name << "/#{scenario.scenario_outline.name}" if scenario.respond_to?(:scenario_outline) name << "/#{scenario.name.split("\n").first}" name else "cucumber_tags/#{tag_name.gsub(/\A@/, '')}" end VCR.insert_cassette(cassette_name, ) end @main_object.After(tag_name) do |scenario| VCR.eject_cassette(:skip_no_unused_interactions_assertion => scenario.failed?) end self.class.add_tag(tag_name) end end |