Tuesday, May 18, 2010

Willful, a light-weight spec'ing library for Node

Last night, I pushed the spec'ing library I made to TDD Campaign Narrative to Github. I'm calling it Willful, well, because it's full of will("do this") and will("do that"). If you're a Javascript hacker, and especially if you're a Node hacker, please check it out and let me know what you think.

Here's an example specification written with Willful:

require("willful");
var assert = require("assert");

// start a new specification:
the("function I'm spec'ing", function (will) {

  // start a new behavior:
  will("exhibit the behavior I expect", function(done) {
    // test something via Node's built-in assert module
    assert.ok(true)

    // signal that the behavior's verification is done
    done();
  });

  // start a second behavior (this one'll fail)
  will("not exhibit the behavior I expect", function(done) {
    assert.equal(true, false);
    done();
  });

});

I looked at many different unit testing and spec'ing libraries when I started to TDD my Node app, and none of them made me quite happy enough. minitest.js came closest, and the design for Willful was influenced by it.

(Bonus: If you look at Willful's own specs, you'll see my approach to stubbing dependencies in Node (such as stubbing sys.puts for reporting). I'll write another 'blog post relating how I came to that approach soon.)

No comments:

Post a Comment