Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: myronmarston/vcr
...
head fork: myronmarston/vcr
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
71 features/test_frameworks/cucumber_scenario_outline.feature
@@ -0,0 +1,71 @@
+Feature: Cucumber with Scenario Outline
+
+ vcr :use_scenario_name works with Scenario Outlines
+
+ @exclude-jruby
+ Scenario: Record HTTP interactions in a scenario by tagging it
+ Given a file named "lib/server.rb" with:
+ """ruby
+ if ENV['WITH_SERVER'] == 'true'
+ start_sinatra_app(:port => 7777) do
+ get('/:path') { "Hello #{params[:path]}" }
+ end
+ end
+ """
+
+ Given a file named "features/support/vcr.rb" with:
+ """ruby
+ require "lib/server"
+ require 'vcr'
+
+ VCR.configure do |c|
+ c.hook_into :fakeweb
+ c.cassette_library_dir = 'features/cassettes'
+ end
+
+ VCR.cucumber_tags do |t|
+ t.tag '@vcr', :use_scenario_name => true
+ end
+ """
+ And a file named "features/step_definitions/steps.rb" with:
+ """ruby
+ require 'net/http'
+
+ When /^a request is made to "([^"]*)"$/ do |url|
+ @response = Net::HTTP.get_response(URI.parse(url))
+ end
+
+ When /^(.*) within a cassette named "([^"]*)"$/ do |step, cassette_name|
+ VCR.use_cassette(cassette_name) { When step }
+ end
+
+ Then /^the response should be "([^"]*)"$/ do |expected_response|
+ @response.body.should == expected_response
+ end
+ """
+ And a file named "features/vcr_example.feature" with:
+ """
+ Feature: VCR example
+
+ Note: Cucumber treats the pre-amble as part of the feature name. When
+ using the :use_scenario_name option, VCR will only use the first line
+ of the feature name as the directory for the cassette.
+
+ @vcr
+ Scenario Outline: scenario outline
+ When a request is made to "http://localhost:7777/localhost_request_1"
+ Then the response should be "Hello localhost_request_1"
+ Examples:
+ | key | value |
+ | foo | bar |
+ """
+ And the directory "features/cassettes" does not exist
+ When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
+ Then it should pass with "1 scenario (1 passed)"
+ And the file "features/cassettes/VCR_example/scenario_outline/_foo_bar_.yml" should contain "Hello localhost_request_1"
+
+ # Run again without the server; we'll get the same responses because VCR
+ # will replay the recorded responses.
+ When I run `cucumber features/vcr_example.feature`
+ Then it should pass with "1 scenario (1 passed)"
+ And the file "features/cassettes/VCR_example/scenario_outline/_foo_bar_.yml" should contain "Hello localhost_request_1"
View
6 lib/vcr/test_frameworks/cucumber.rb
@@ -40,7 +40,11 @@ def tags(*tag_names)
options = original_options.dup
cassette_name = if options.delete(:use_scenario_name)
- "#{scenario.feature.name.split("\n").first}/#{scenario.name}"
+ feature = scenario.respond_to?(:scenario_outline) ? scenario.scenario_outline.feature : scenario.feature
+ file_name = feature.name.split("\n").first
+ file_name << "/#{scenario.scenario_outline.name}" if scenario.respond_to?(:scenario_outline)
+ file_name << "/#{scenario.name}"
+ file_name
else
"cucumber_tags/#{tag_name.gsub(/\A@/, '')}"
end
View
9 spec/vcr/test_frameworks/cucumber_spec.rb
@@ -61,6 +61,15 @@ def test_tag(cassette_attribute, tag, expected_value, scenario=current_scenario)
test_tag(:name, 'tag1', 'My feature name/My scenario name')
end
+ it "makes a unique name for each element of scenario outline" do
+ subject.send(tag_method, 'tag1', :use_scenario_name => true)
+
+ scenario_with_outline = stub(:name => "My row name",
+ :scenario_outline => stub(:feature => stub(:name => "My feature name\nThe preamble text is not included"),
+ :name => "My scenario outline name"))
+ test_tag(:name, 'tag1', 'My feature name/My scenario outline name/My row name', scenario_with_outline)
+ end
+
it 'does not pass :use_scenario_name along the given options to the cassette' do
subject.send(tag_method, 'tag1', :use_scenario_name => true)

No commit comments for this range

Something went wrong with that request. Please try again.