From 3072661f6bc8e3d5d5bdf77e24fb38cf6c9b3e07 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Fri, 12 Sep 2014 16:09:44 +0200 Subject: [PATCH] Don't skip scenario outlines (close #245) --- features/scenario_outlines.feature | 58 ++++++++++++++++++--------- lib/cucumber/ast/feature.js | 4 +- lib/cucumber/type/collection.js | 3 +- spec/cucumber/type/collection_spec.js | 10 +++-- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/features/scenario_outlines.feature b/features/scenario_outlines.feature index b556e6100..368e6f134 100644 --- a/features/scenario_outlines.feature +++ b/features/scenario_outlines.feature @@ -7,7 +7,7 @@ Feature: Scenario Outlines and Examples Background: Given a background step - Scenario Outline: outline + Scenario Outline: basic outline When a step Then i get Examples: @@ -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 @@ -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 | | | | @@ -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 @@ -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 step - Then i get - Examples: - | some | result | - | passing | passed | - | failing | skipped | \ No newline at end of file + """ + 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 + + Examples: + | id | + | a | + | b | + + Scenario Outline: scenario outline 2 + When step + + 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 diff --git a/lib/cucumber/ast/feature.js b/lib/cucumber/ast/feature.js index 592d35506..8fc3eeb1d 100644 --- a/lib/cucumber/ast/feature.js +++ b/lib/cucumber/ast/feature.js @@ -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) { @@ -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); diff --git a/lib/cucumber/type/collection.js b/lib/cucumber/type/collection.js index 9a5f1d5fa..77a5193a6 100644 --- a/lib/cucumber/type/collection.js +++ b/lib/cucumber/type/collection.js @@ -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) { diff --git a/spec/cucumber/type/collection_spec.js b/spec/cucumber/type/collection_spec.js index f7a6a0c4e..6ae54d7b7 100644 --- a/spec/cucumber/type/collection_spec.js +++ b/spec/cucumber/type/collection_spec.js @@ -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); }); }); }); -