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.
If you're seeing this message you've probably enabled some form of adblocker. I respect that.
I use this space to show recommended books on Amazon.com in relation to the post you just read. This generates a small income that allows me to buy a book every now and then.