Created
September 4, 2010 07:41
-
-
Save bnoguchi/564996 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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, callbackGenerator) { | |
thens[pattern] = callbackGenerator; | |
}); | |
Given(/^I have a httpServer$/, function () { | |
return function (topic) { | |
// Always use or extend the same topic since you don't know how nested or not nested you are at this point | |
topic = topic || {}; | |
topic.server = require("http").createServer().listen(8080); | |
return topic; | |
}; | |
}); | |
Given(/^my httpServer responds with "(.+)"$/, function (responseBody) { | |
return function (topic) { | |
topic = topic || {}; | |
topic.server.on("request", function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end(responseBody + '\n'); | |
}); | |
return topic; | |
}; | |
}); | |
When(/^I make a request$/, function () { | |
return function (topic) { | |
topic = topic || {}; | |
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. | |
}); |
This file contains hidden or 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
Given I have a httpServer | |
And my httpServer responds with "Hello World" | |
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