Skip to content

Commit

Permalink
Don't skip scenario outlines (close #245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Sep 12, 2014
1 parent c38d63a commit 3072661
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
58 changes: 40 additions & 18 deletions features/scenario_outlines.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: Scenario Outlines and Examples
Background:
Given a background step
Scenario Outline: outline
Scenario Outline: basic outline
When a <some> step
Then i get <result>
Examples:
Expand All @@ -21,7 +21,7 @@ Feature: Scenario Outlines and Examples
And the step "i get passed" has a passing mapping
And the step "i get skipped" has a passing mapping
When Cucumber runs the feature
Then the scenario called "outline" is reported as failing
Then the scenario called "basic outline" is reported as failing
And the step "a background step" passes
And the step "a passing step" passes
And the step "a failing step" passes
Expand All @@ -30,9 +30,9 @@ Feature: Scenario Outlines and Examples

Scenario: Outline with table
Given the following feature:
"""
"""
Feature: testing scenarios
Scenario Outline: outline
Scenario Outline: outline with table
When a table step:
| first | second |
| <first> | <second> |
Expand All @@ -49,9 +49,9 @@ Feature: Scenario Outlines and Examples

Scenario: Outline with doc string
Given the following feature:
"""
"""
Feature: testing scenarios
Scenario Outline: outline
Scenario Outline: outline with doc string
When a doc string step:
\"\"\"
I am doc string in <example> example
Expand All @@ -64,15 +64,37 @@ Feature: Scenario Outlines and Examples
And the step "a doc string step:" has a passing mapping that receives a doc string
When Cucumber runs the feature
Then the received doc string equals the following:
"""
I am doc string in first example
And there are some string
"""

Scenario Outline: outline
When a <some> step
Then i get <result>
Examples:
| some | result |
| passing | passed |
| failing | skipped |
"""
I am doc string in first example
And there are some string
"""

Scenario: Several outlines
Given the following feature:
"""
Feature: testing scenarios
Scenario Outline: scenario outline 1
When step <id>
Examples:
| id |
| a |
| b |
Scenario Outline: scenario outline 2
When step <id>
Examples:
| id |
| c |
| d |
"""
And the step "step a" has a passing mapping
And the step "step b" has a passing mapping
And the step "step c" has a passing mapping
And the step "step d" has a passing mapping
When Cucumber runs the feature
Then the step "step a" passes
And the step "step b" passes
And the step "step c" passes
And the step "step d" passes
4 changes: 2 additions & 2 deletions lib/cucumber/ast/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var Feature = function(keyword, name, description, uri, line) {
addFeatureElement: function addFeatureElement(featureElement) {
var background = self.getBackground();
featureElement.setBackground(background);
featureElements.add(featureElement);
featureElements.add(featureElement);
},

insertFeatureElement: function insertFeatureElement(index, featureElement) {
Expand All @@ -57,7 +57,7 @@ var Feature = function(keyword, name, description, uri, line) {
}
});
},

convertScenarioOutlineToScenarios: function convertScenarioOutlineToScenarios(scenarioOutline) {
var scenarios = scenarioOutline.buildScenarios();
var scenarioOutlineIndex = featureElements.indexOf(scenarioOutline);
Expand Down
3 changes: 2 additions & 1 deletion lib/cucumber/type/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var Collection = function () {
},

syncForEach: function syncForEach(userFunction) {
items.forEach(userFunction);
var itemsCopy = items.slice(0);
itemsCopy.forEach(userFunction);
},

forEach: function forEach(userFunction, callback) {
Expand Down
10 changes: 6 additions & 4 deletions spec/cucumber/type/collection_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ describe("Cucumber.Type.Collection", function() {
describe("syncForEach()", function() {
var userFunction = createSpy("userFunction");

it("calls foreach on the array", function() {
spyOn(itemArray, 'forEach');
it("calls foreach on a copy of the array", function() {
var itemsCopy = createSpy("items copy");
spyOn(itemArray, 'slice').andReturn(itemsCopy);
spyOnStub(itemsCopy, 'forEach');
collection.syncForEach(userFunction);
expect(itemArray.forEach).toHaveBeenCalledWith(userFunction);
expect(itemArray.slice).toHaveBeenCalledWith(0);
expect(itemsCopy.forEach).toHaveBeenCalledWith(userFunction);
});
});
});

0 comments on commit 3072661

Please sign in to comment.