Skip to content

Instantly share code, notes, and snippets.

@Marak
Forked from tim-smart/vows_callback.js
Created June 22, 2010 23:25
Show Gist options
  • Select an option

  • Save Marak/449263 to your computer and use it in GitHub Desktop.

Select an option

Save Marak/449263 to your computer and use it in GitHub Desktop.
// HttpClient only calls 'success' once.
var respondsWith = function (code, body) {
var context = {
topic: function () {
var req = this.context.name.split(/ +/), // ["POST", "/"]
method = req[0].toLowerCase(), // "post"
path = req[1], // "/"
self = this;
new HttpClient({
method: method,
url: HOST + path,
success: function (response) {
self.callback(null, response);
}
}).end();
}
};
context['should respond with ' + code + ', ' + body] = function (err, response) {
assert.equal(code, response.statusCode);
assert.equal(body, response.body.toString('utf8'));
};
return context;
}
// My tests
vow.addBatch({
"GET /": respondsWith(200, "Some text")
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment