Feature: Simple maths
In order to do maths
As a developer
I want to increment variables
Scenario: easy maths
Given a variable set to 1
When I increment the variable by 1
Then the variable should contain 2
Scenario Outline: much more complex stuff
Given a variable set to <var>
When I increment the variable by <increment>
Then the variable should contain <result>
Examples:
| var | increment | result |
| 100 | 5 | 105 |
| 99 | 1234 | 1333 |
| 12 | 5 | 18 |
// Cucumber and chai have been loaded in the browser
var setWorldConstructor = Cucumber.setWorldConstructor;
var Given = Cucumber.Given;
var When = Cucumber.When;
var Then = Cucumber.Then;
var expect = chai.expect;
///// World /////
//
// Call 'setWorldConstructor' with to your custom world (optional)
//
var CustomWorld = function() {
this.variable = 0;
};
CustomWorld.prototype.setTo = function(number) {
this.variable = parseInt(number);
};
CustomWorld.prototype.incrementBy = function(number) {
this.variable += parseInt(number);
};
setWorldConstructor(CustomWorld);
///// Step definitions /////
//
// use 'Given', 'When' and 'Then' to declare step definitions
//
Given('a variable set to {int}', function(number) {
this.setTo(number);
});
When('I increment the variable by {int}', function(number) {
this.incrementBy(number);
});
Then('the variable should contain {int}', function(number) {
expect(this.variable).to.eql(number)
});