Skip to content
Browse files

Properly tag scenario outlines (close #195 #197)

This fixes tag filtering on scenario outlines.
  • Loading branch information...
1 parent f5b4f6c commit cb5249d6a6b30d5cdf637186f1f69d122c5175af @akania akania committed with jbpros
Showing with 89 additions and 3 deletions.
  1. +14 −1 lib/cucumber/ast/assembler.js
  2. +75 −2 spec/cucumber/ast/assembler_spec.js
View
15 lib/cucumber/ast/assembler.js
@@ -83,6 +83,16 @@ var Assembler = function (features, filter) {
}
},
+ insertOutlineScenario: function insertOutlineScenario(scenario, tags) {
+ self.applyCurrentFeatureTagsToElement(scenario);
+ scenario.addTags(tags);
+ self.setCurrentScenarioOrBackground(scenario);
+ if (filter.isElementEnrolled(scenario)) {
+ var currentFeature = self.getCurrentFeature();
+ currentFeature.addFeatureElement(scenario);
+ }
+ },
+
insertExamples: function insertExamples(examples) {
var currentScenarioOrBackground = self.getCurrentScenarioOrBackground();
if (currentScenarioOrBackground.payloadType == 'scenarioOutline')
@@ -104,7 +114,10 @@ var Assembler = function (features, filter) {
convertScenarioOutlineToScenarios: function convertScenarioOutlineToScenarios(scenario){
var subScenarios = scenario.buildScenarios();
- subScenarios.syncForEach(self.insertScenario);
+ var subScenarioTags = scenario.getTags();
+ subScenarios.syncForEach(function (scenario) {
+ self.insertOutlineScenario(scenario, subScenarioTags);
+ });
},
convertScenarioOutlinesToScenarios: function convertScenarioOutlinesToScenarios(){
View
77 spec/cucumber/ast/assembler_spec.js
@@ -309,6 +309,73 @@ describe("Cucumber.Ast.Assembler", function() {
});
});
+ describe("insertOutlineScenario()", function() {
+ var scenario, currentFeature, tags;
+
+ beforeEach(function() {
+ tags = ['@test', '@test1'];
+ scenario = createSpy("scenario");
+ scenario.addTags = createSpy("addTags");
+ currentFeature = createSpyWithStubs("current feature", {addFeatureElement: null});
+ spyOnStub(filter, 'isElementEnrolled');
+ spyOn(assembler, 'applyCurrentFeatureTagsToElement');
+ spyOn(assembler, 'getCurrentFeature').andReturn(currentFeature);
+ spyOn(assembler, 'setCurrentScenarioOrBackground');
+ });
+
+ it("applies the current feature tags to the scenario", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(assembler.applyCurrentFeatureTagsToElement).toHaveBeenCalledWith(scenario);
+ });
+
+ it("applies custom tags to the scenario", function() {
+ assembler.insertOutlineScenario(scenario, tags);
+ expect(scenario.addTags).toHaveBeenCalledWith(tags);
+ });
+
+ it("sets the scenario as the current scenario", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(assembler.setCurrentScenarioOrBackground).toHaveBeenCalledWith(scenario);
+ });
+
+ it("asks the filter if the scenario is enrolled", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(filter.isElementEnrolled).toHaveBeenCalledWith(scenario);
+ });
+
+ describe("when the scenario is enrolled", function() {
+ beforeEach(function() {
+ filter.isElementEnrolled.andReturn(true);
+ });
+
+ it("gets the current feature", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(assembler.getCurrentFeature).toHaveBeenCalled();
+ });
+
+ it("adds the scenario to the current feature", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(currentFeature.addFeatureElement).toHaveBeenCalledWith(scenario);
+ });
+ });
+
+ describe("when the scenario is not enrolled", function() {
+ beforeEach(function() {
+ filter.isElementEnrolled.andReturn(false);
+ });
+
+ it("does not get the current feature", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(assembler.getCurrentFeature).not.toHaveBeenCalled();
+ });
+
+ it("does not add the scenario to the current feature", function() {
+ assembler.insertOutlineScenario(scenario);
+ expect(currentFeature.addFeatureElement).not.toHaveBeenCalledWith(scenario);
+ });
+ });
+ });
+
describe("insertStep()", function() {
var step, currentScenario;
@@ -357,13 +424,19 @@ describe("Cucumber.Ast.Assembler", function() {
subScenarios.add(subScenario);
scenarioOutline = createSpyWithStubs('scenario', {'buildScenarios': subScenarios});
scenarioOutline.payload_type = 'scenarioOutline';
+ scenarioOutline.getTags = function () { return '@test'; };
- spyOn(assembler, 'insertScenario');
+ spyOn(assembler, 'insertOutlineScenario');
});
it("it should get the scenarios from the current feature", function () {
assembler.convertScenarioOutlineToScenarios(scenarioOutline);
- expect(assembler.insertScenario).toHaveBeenCalledWithValueAsNthParameter(subScenario,1);
+ expect(assembler.insertOutlineScenario).toHaveBeenCalledWithValueAsNthParameter(subScenario,1);
+ });
+
+ it("it should pass tags from scenario outline to all subscenarios", function () {
+ assembler.convertScenarioOutlineToScenarios(scenarioOutline);
+ expect(assembler.insertOutlineScenario).toHaveBeenCalledWithValueAsNthParameter('@test',2);
});
});

0 comments on commit cb5249d

Please sign in to comment.
Something went wrong with that request. Please try again.