diff --git a/README.md b/README.md index 409c80e..12fe1b8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ _Vows_ is an experiment in making this possible, while adding a minimum of overh synopsis -------- - + var vows = require('vows'), assert = require('assert'); @@ -25,7 +25,7 @@ synopsis In the example above, `question()` would be a function which returns an `EventEmitter`. When the `"success"` event is emitted, the function passed to `addVow` is run, -and the results output to the console. +and the results output to the console. Vows are run as soon as the promise completes, so the order in which they are run is undefined. @@ -38,33 +38,35 @@ writing specs ------------- vows.describe('A Database library').addVows({ - // run this once, and execute the following tests when it completes - topic: function () { return new(DB) }, - - 'set() should store a k/v pair': { - // the inner context gets the return values of the outer contexts - // passed as arguments. Here, `db` is new(DB). - topic: function (db) { return db.set('pulp', 'orange') }, - - // `res` is the value emitted by the above `db.set` - 'and return OK': function (res) { - assert.equal(res, "OK"); + 'A DB object': { + // run this once, and execute the following tests when it completes + topic: function () { return new(DB) }, + + 'set() should store a k/v pair': { + // the inner context gets the return values of the outer contexts + // passed as arguments. Here, `db` is new(DB). + topic: function (db) { return db.set('pulp', 'orange') }, + + // `res` is the value emitted by the above `db.set` + 'and return OK': function (res) { + assert.equal(res, "OK"); + }, + 'and when checked for existence': { + // here, we need to access `db`, from the parent context. + // It's passed as the 2nd argument to `topic`, we discard the first, + // which would have been the above `res`. + topic: function (_, db) { return db.exists('pulp') }, + + 'return true': function (re) { + assert.equal(re, true); + } + } }, - 'and when checked for existence': { - // here, we need to access `db`, from the parent context. - // It's passed as the 2nd argument to `topic`, we discard the first, - // which would have been the above `res`. - topic: function (_, db) { return db.exists('pulp') }, - - 'return true': function (re) { - assert.equal(re, true); + 'get()': { + topic: function (db) { return db.get('dream') }, + 'should return the stored value': function (res) { + assert.equal(res, 'catcher'); } } - }, - 'get()': { - topic: function (db) { return db.get('dream') }, - 'should return the stored value': function (res) { - assert.equal(res, 'catcher'); - } } }); diff --git a/lib/vows.js b/lib/vows.js index 784192c..c0b1856 100644 --- a/lib/vows.js +++ b/lib/vows.js @@ -210,6 +210,9 @@ function addVows(tests) { vows.promises.push(promise); if (typeof(tests) === 'object') { + if ('topic' in tests) { + throw new(Error)("Missing top-level context."); + } // Count the number of vows/promises expected to fire, // so we know when the tests are over. // We match the keys against `matcher`, to decide