Skip to content

Instantly share code, notes, and snippets.

@keerts
Created February 6, 2014 16:58
Show Gist options
  • Save keerts/8848223 to your computer and use it in GitHub Desktop.
Save keerts/8848223 to your computer and use it in GitHub Desktop.
cucumber.js, a more functional example (stepdefinition.js)
var Q = require('q');
var _ = require('lodash');
var myStepDefinitionsWrapper = function() {
this.World = require("../support/world.js").World; // overwrite default World constructor
this.Given(/^there are (\d+) events$/, function(count, callback) {
var self = this;
var arr = _.times(count, function(i) {
return createEvent.call(self, i);
})
Q.all(arr).then(function(arr) {
callback()
}).done();
});
var createEvent = function(identifier) {
return this.post('/events', { name : "event " + identifier, description : "cool event", price : { currency : "EUR", amount : 10000}, tickets : 200, status : "OPEN"});
};
this.When(/^I create a new event$/, function(callback) {
createEvent.call(this, "new event").then(function(_) {
callback()
});
});
this.Then(/^there will be (\d+) event[s]?$/, function(count, callback) {
this.get('/events').then(
function(response) {
if (count == response.total_rows) {
callback()
} else {
callback.fail()
}
}).done();
});
// etc...
}
module.exports = myStepDefinitionsWrapper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment