Thursday, July 1st, 2010
Keep your vows; Keeping wed to Node
Vows can be a beautiful thing. Alexis Sellier of LESS fame, is becoming an open source star. This time around he brings us Vows an asynchronous-friendly behavior driven development framework for Node.js.
Write you BBD specs like this:
- // division-by-zero-test.js
- var vows = require('vows'),
- assert = require('assert');
- // Create a Test Suite
- vows.describe('Division by Zero').addBatch({
- 'when dividing a number by zero': {
- topic: function () { return 42 / 0 },
- 'we get Infinity': function (topic) {
- assert.equal (topic, Infinity);
- }
- },
- 'but when dividing zero by zero': {
- topic: function () { return 0 / 0 },
- 'we get a value which': {
- 'is not a number': function (topic) {
- assert.isNaN (topic);
- },
- 'is not equal to itself': function (topic) {
- assert.notEqual (topic, topic);
- }
- }
- }
- }).run(); // Run it
and you get a very nice report card out of the other end:
With macros you end up with very nice DSL syntax such as:
- { 'GET /': {
- topic: api.get('/'),
- 'shoud respond with a 200 OK': assertStatus(200)
- },
- 'POST /': {
- topic: api.post('/'),
- 'shoud respond with a 405 Method not allowed': assertStatus(405)
- },
- 'GET /resources (no api-key)': {
- topic: api.get('/resources'),
- 'shoud respond with a 403 Forbidden': assertStatus(403)
- },
- 'GET /resources?apikey=af816e859c249fe'
- topic: api.get('/resources?apikey=af816e859c249fe'),
- 'shoud return a 200 OK': assertStatus(200),
- 'should return a list of resources': function (res) {
- assert.isArray (res.body);
- }
- }
- }
- // or even
- {
- 'GET /': respondsWith(200),
- 'POST /': respondsWith(405),
- 'GET /resources (no key)': respondsWith(403)
- }
The website itself goes into exquisite detail on the install process, sample usage, and more. The website also happens to be beautiful itself, and full of HTML5 markup to boot.





Sexy site and sexy-looking tool :) Javascript is an awesome language.