indexzero
10/28/2010 - 7:16 PM

vows-journey-web-service.js

vows-journey-web-service.js

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);
$ 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)