First off, make sure you have CoffeeScript and Vows installed. Here I
install them globally so you can use the
npm install -g coffee-script npm install -g vows
Next up, in your product directory, create a directory named
Here we’ll create (classic) example:
vows = require 'vows' assert = require 'assert' vows .describe('Division by zero') .addBatch 'when dividing a number by zero': topic: -> 42/ 0 'we get Infinity': (topic) -> assert.equal topic, Infinity 'but when dividing zero by zero': topic: -> 0 / 0 'we get a value which': 'is not a number': (topic) -> assert.isNaN topic 'is not equal to itself': (topic) -> assert.notEqual topic, topic .export(module)
I’m not going to explain the intimate details of Vows here, suffice it
to say that you calculate a value and store it in
topic. Then you
perform a set of expectations.
The magic part is the last line,
.export(module). In all other
examples you’ll see the last command is
runs your vows immediately.
test/division-test.coffee saved, try running
your console. Here’s the output from
vows --spec ♢ Division by zero when dividing a number by zero ✓ we get Infinity but when dividing zero by zero we get a value which ✓ is not a number ✓ is not equal to itself ✓ OK » 3 honored (0.002s)
Another great tip is
vows -w. This will keep vows running and monitor
your test files for changes. When a file changes, it will re-run your
vows for you.
Yes, I know there are issues with Coderay parsing UTF-8 characters.
Want to keep reading and learn more? I've got you
covered with a hand picked selection of awesome books.