Created
February 6, 2014 16:58
-
-
Save keerts/8848223 to your computer and use it in GitHub Desktop.
cucumber.js, a more functional example (stepdefinition.js)
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
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