Skip to content

Commit

Permalink
Collapse cucumber scenario outline feature into cucumber feature. Ref…
Browse files Browse the repository at this point in the history
…actor cucumber.rb naming code. Add spec.
  • Loading branch information
Jacob Green committed Sep 7, 2012
1 parent a39a8e3 commit b6815b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 89 deletions.
16 changes: 14 additions & 2 deletions features/test_frameworks/cucumber.feature
Expand Up @@ -27,6 +27,8 @@ Feature: Usage with Cucumber
You can also have VCR name your cassettes automatically according to the feature
and scenario name by providing :use_scenario_name => true to '#tag' or '#tags'.
In this case, the cassette will be named "<feature_name>/<scenario_name>".
For scenario outlines, VCR will record one cassette per row, and the cassettes
will be named "<feature_name>/<scenario_name>/<row_name>.
@exclude-jruby
Scenario: Record HTTP interactions in a scenario by tagging it
Expand Down Expand Up @@ -93,6 +95,14 @@ Feature: Usage with Cucumber
When a request is made to "http://localhost:7777/localhost_request_1"
Then the response should be "Hello localhost_request_1"
@vcr
Scenario Outline: tagged 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 |
@disallowed_1
Scenario: tagged scenario
When a request is made to "http://localhost:7777/allowed" within a cassette named "allowed"
Expand All @@ -105,7 +115,7 @@ Feature: Usage with Cucumber
"""
And the directory "features/cassettes" does not exist
When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
Then it should fail with "4 scenarios (2 failed, 2 passed)"
Then it should fail with "5 scenarios (2 failed, 3 passed)"
And the output should contain each of the following:
| An HTTP request has been made that VCR does not know how to handle: |
| GET http://localhost:7777/disallowed_1 |
Expand All @@ -116,11 +126,12 @@ Feature: Usage with Cucumber
And the file "features/cassettes/nested_cassette.yml" should contain "Hello nested_cassette"
And the file "features/cassettes/allowed.yml" should contain "Hello allowed"
And the file "features/cassettes/VCR_example/tagged_scenario.yml" should contain "Hello localhost_request_1"
And the file "features/cassettes/VCR_example/tagged_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 fail with "4 scenarios (2 failed, 2 passed)"
Then it should fail with "5 scenarios (2 failed, 3 passed)"
And the output should contain each of the following:
| An HTTP request has been made that VCR does not know how to handle: |
| GET http://localhost:7777/disallowed_1 |
Expand All @@ -131,3 +142,4 @@ Feature: Usage with Cucumber
And the file "features/cassettes/nested_cassette.yml" should contain "Hello nested_cassette"
And the file "features/cassettes/allowed.yml" should contain "Hello allowed"
And the file "features/cassettes/VCR_example/tagged_scenario.yml" should contain "Hello localhost_request_1"
And the file "features/cassettes/VCR_example/tagged_scenario_outline/_foo_bar_.yml" should contain "Hello localhost_request_1"
71 changes: 0 additions & 71 deletions features/test_frameworks/cucumber_scenario_outline.feature

This file was deleted.

24 changes: 8 additions & 16 deletions lib/vcr/test_frameworks/cucumber.rb
Expand Up @@ -40,22 +40,14 @@ def tags(*tag_names)
options = original_options.dup

cassette_name = if options.delete(:use_scenario_name)
case scenario
when Cucumber::Ast::Scenario
File.join(scenario.feature.name.split("\n").first, scenario.name)
when Cucumber::Ast::ScenarioOutline
# This happens if we trigger a Scenario Outline
# in isolation. First example row is not accessible.
File.join(scenario.feature.name.split("\n").first, scenario.name, 'first_example')
when Cucumber::Ast::OutlineTable::ExampleRow
# ExampleRow's scenario.name holds the example itself
File.join(scenario.scenario_outline.feature.name.split("\n").first, scenario.scenario_outline.name, scenario.name)
else
raise "Unhandled class: #{scenario.class.name}"
end
else
"cucumber_tags/#{tag_name.gsub(/\A~?@/, '')}"
end
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}"
name
else
"cucumber_tags/#{tag_name.gsub(/\A@/, '')}"
end

VCR.insert_cassette(cassette_name, options)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/vcr/test_frameworks/cucumber_spec.rb
Expand Up @@ -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)

Expand Down

0 comments on commit b6815b5

Please sign in to comment.