Sha256: c383c2a4a4d1f4e8c9069de0962bb9d6cb59b64deced800eac607258c2012282
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
module VCR # Provides integration with Cucumber using tags. class CucumberTags class << self # @private def tags @tags.dup end # @private def add_tag(tag) @tags << tag end end @tags = [] # @private def initialize(main_object) @main_object = main_object end # Adds +Before+ and +After+ cucumber hooks for the named tags that # will cause a VCR cassette to be used for scenarios with matching tags. # # @param [Array<String>] tag_names the cucumber scenario tags # @param [(optional) Hash] options the cassette options. Specify :use_scenario_name => true to automatically name the cassette according to the scenario name. def tags(*tag_names) options = tag_names.last.is_a?(::Hash) ? tag_names.pop : {} tag_names.each do |tag_name| tag_name = "@#{tag_name}" unless tag_name =~ /\A@/ cassette_name = "cucumber_tags/#{tag_name.gsub(/\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| options = options.dup cassette_name = "#{scenario.feature.name}/#{scenario.name}" if options.delete(:use_scenario_name) VCR.insert_cassette(cassette_name, options) end @main_object.After(tag_name) do VCR.eject_cassette end self.class.add_tag(tag_name) end end alias :tag :tags end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vcr-2.1.0 | lib/vcr/test_frameworks/cucumber.rb |