Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#195 - tag every scenario from scenario outline with scenario outline ta... #197

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/cucumber/ast/assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(){
Expand Down
77 changes: 75 additions & 2 deletions spec/cucumber/ast/assembler_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
});

Expand Down