Skip to content

Instantly share code, notes, and snippets.

@Marak
Forked from bnoguchi/hackety.js
Created September 4, 2010 07:43
Show Gist options
  • Save Marak/564998 to your computer and use it in GitHub Desktop.
Save Marak/564998 to your computer and use it in GitHub Desktop.
var givens = {};
var Given = function (pattern, topicGenerator) {
givens[pattern] = topicGenerator;
};
var whens = {};
var When = function (pattern, topicGenerator) {
whens[pattern] = topicGenerator;
};
var thens = {};
var Then = function (pattern, callback) {
thens[pattern] = callback;
});
Given(/^I have a hello world httpServer$/, function () {
return require("http").createServer().listen(8080);
});
When(/^I make a request$/, function () {
var client = require("http").createClient(8080, "localhost");
var req = client.request("GET", "/");
req.end();
req.on("response", function (res) {
res.on("data", function (data) {
this.callback(data);
});
});
});
Then(/^I should see "(.+)"$/, function (str) {
return function (data) { // The callback
assert.equal(data, str);
};
});
fs.readFile("./httpServer.feature", function (err, data) {
data.split("\n");
// Parse out Givens, Whens, Thens
// Match via givens, whens, and thens maps defined in step defs
// Use mapped values in a vows structure.
});
Given I have a hello world httpServer
When I make a request
Then I should see "Hello World"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment