Skip to content

Commit

Permalink
Add ability to circumvent addBatch
Browse files Browse the repository at this point in the history
This makes it possible to skip the calls to `addBatch` by using optional
parameters inside the `describe` method.  This is a small change that
allows the developer to focus on the code of the tests, thinking of it
think of them in terms of data structure instead of Vows' API.

The less that the Vows API is present in a test case, the less
distracting it is.  With this, you could choose to focus solely on the
structure of the test and ignore Vows is present by importing only
`describe`.

This is an entirely backwards compatible change that does not effect any
other code.  It is fully tested inside the existing tests.
  • Loading branch information
tswicegood authored and Alexis Sellier committed Jul 2, 2010
1 parent 36c5c47 commit db57e70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ vows.describe = function (subject) {
this.options.Emitter.prototype.addVow = addVow;
this.suites.push(suite);

//
// Add any additional arguments as batches if they're present
//
if (arguments.length > 1) {
for (var i = 1, l = arguments.length; i < l; ++i) {
suite.addBatch(arguments[i]);
}
}

return suite;
};

Expand Down
21 changes: 21 additions & 0 deletions test/vows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,24 @@ vows.describe("Vows").addBatch({
topic: true, "should run last": function () {}
}
}).addBatch({}).export(module);

vows.describe("Vows with a single batch", {
"This is a batch that's added as the optional parameter to describe()": {
topic: true,
"A batch added without calling addBatch()": function() {}
}
}).export(module);


vows.describe("Vows with multiple batches added as optional parameters", {
"First batch": {
topic: true,
"should be run first": function() {}
}
}, {
"Second batch": {
topic: true,
"should be run second": function() {}
}
}).export(module);

0 comments on commit db57e70

Please sign in to comment.