Skip to content

Commit

Permalink
throw Error if missing top-level context
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed May 19, 2010
1 parent 9294ed8 commit 3f4bbec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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.

Expand All @@ -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');
}
}
});
3 changes: 3 additions & 0 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f4bbec

Please sign in to comment.