Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created October 28, 2010 19:16
Show Gist options
  • Save indexzero/652118 to your computer and use it in GitHub Desktop.
Save indexzero/652118 to your computer and use it in GitHub Desktop.
vows-journey-web-service.js
$ vows sample.js --spec
The 'sys' module is now called 'util'. It should have a similar interface.
♢ some/sample/test
When using my test server any http request
✓ should respond with hello world
When the tests are complete
✓ stop the test server
✓ OK » 2 honored (0.005s)
var vows = require('vows'),
assert = require('assert'),
http = require('http'),
request = require('request'); // npm install request
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello world');
res.end();
});
server.listen(8080);
vows.describe('some/sample/test').addBatch({
"When using my test server": {
"any http request": {
topic: function () {
request({ uri: 'http://127.0.0.1:8080' }, this.callback);
},
"should respond with hello world": function (err, res, body) {
assert.equal(body, 'hello world');
assert.equal(res.statusCode, 200);
}
}
}
}).addBatch({
"When the tests are complete": {
"stop the test server": function () {
server.close();
}
}
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment