Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for background (close #9)
- Loading branch information
Showing
13 changed files
with
626 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Feature: Background | ||
|
||
Background allows you to add some context to the scenarios in a | ||
single feature. A Background is much like a scenario containing a | ||
number of steps. The difference is when it is run. The background is | ||
run before each of your scenarios but after any of your Before | ||
Hooks. | ||
|
||
Scenario: One scenario and a background | ||
Given the following feature: | ||
""" | ||
Feature: testing scenarios | ||
Background: | ||
Given a background step | ||
Scenario: | ||
When a scenario step | ||
""" | ||
And the step "a background step" has a passing mapping | ||
And the step "a scenario step" has a passing mapping | ||
When Cucumber runs the feature | ||
Then the feature passes | ||
And the step "a background step" passes | ||
And the step "a scenario step" passes | ||
|
||
Scenario: Two scenarios and a background | ||
Given the following feature: | ||
""" | ||
Feature: testing scenarios | ||
Background: | ||
Given a background step | ||
Scenario: | ||
When a scenario step | ||
Scenario: | ||
When a second scenario step | ||
""" | ||
And the step "a background step" has a passing mapping | ||
And the step "a scenario step" has a passing mapping | ||
And the step "a second scenario step" has a passing mapping | ||
When Cucumber runs the feature | ||
Then the feature passes | ||
# todo: ensure the background step is called twice | ||
And the step "a background step" passes | ||
And the step "a scenario step" passes | ||
And the step "a second scenario step" passes | ||
|
||
# TODO: failing background steps, failing scenario steps... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var Background = function(keyword, name, description, line) { | ||
var Cucumber = require('../../cucumber'); | ||
|
||
var steps = Cucumber.Type.Collection(); | ||
|
||
var self = { | ||
getKeyword: function getKeyword() { | ||
return keyword; | ||
}, | ||
|
||
getName: function getName() { | ||
return name; | ||
}, | ||
|
||
getDescription: function getDescription() { | ||
return description; | ||
}, | ||
|
||
getLine: function getLine() { | ||
return line; | ||
}, | ||
|
||
addStep: function addStep(step) { | ||
steps.add(step); | ||
}, | ||
|
||
getLastStep: function getLastStep() { | ||
return steps.getLast(); | ||
}, | ||
|
||
getSteps: function getSteps() { | ||
return steps; | ||
} | ||
}; | ||
return self; | ||
}; | ||
module.exports = Background; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require('../../support/spec_helper'); | ||
|
||
describe("Cucumber.Ast.Background", function() { | ||
var Cucumber = require('cucumber'); | ||
var steps; | ||
var background, keyword, name, description, line, lastStep; | ||
|
||
beforeEach(function() { | ||
keyword = createSpy("background keyword"); | ||
name = createSpy("background name"); | ||
description = createSpy("background description"); | ||
line = createSpy("starting background line number"); | ||
lastStep = createSpy("Last step"); | ||
steps = createSpy("Step collection"); | ||
spyOnStub(steps, 'add'); | ||
spyOnStub(steps, 'getLast').andReturn(lastStep); | ||
spyOn(Cucumber.Type, 'Collection').andReturn(steps); | ||
background = Cucumber.Ast.Background(keyword, name, description, line); | ||
}); | ||
|
||
describe("constructor", function() { | ||
it("creates a new collection to store steps", function() { | ||
expect(Cucumber.Type.Collection).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("getKeyword()", function() { | ||
it("returns the keyword of the background", function() { | ||
expect(background.getKeyword()).toBe(keyword); | ||
}); | ||
}); | ||
|
||
describe("getName()", function() { | ||
it("returns the name of the background", function() { | ||
expect(background.getName()).toBe(name); | ||
}); | ||
}); | ||
|
||
describe("getDescription()", function() { | ||
it("returns the description of the background", function() { | ||
expect(background.getDescription()).toBe(description); | ||
}); | ||
}); | ||
|
||
describe("getLine()", function() { | ||
it("returns the line on which the background starts", function() { | ||
expect(background.getLine()).toBe(line); | ||
}); | ||
}); | ||
|
||
describe("addStep()", function() { | ||
it("adds the step to the steps (collection)", function() { | ||
var step = createSpy("step AST element"); | ||
background.addStep(step); | ||
expect(steps.add).toHaveBeenCalledWith(step); | ||
}); | ||
}); | ||
|
||
describe("getLastStep()", function() { | ||
it("gets the last step from the collection", function() { | ||
background.getLastStep(); | ||
expect(steps.getLast).toHaveBeenCalled(); | ||
}); | ||
|
||
it("returns that last step from the collection", function() { | ||
expect(background.getLastStep()).toBe(lastStep); | ||
}); | ||
}); | ||
|
||
describe("getSteps()", function() { | ||
it("returns the steps", function() { | ||
expect(background.getSteps()).toBe(steps); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.