Skip to content

Commit

Permalink
(new) basic teardown support
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Aug 25, 2010
1 parent 7cdf94f commit c3ad80d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/vows/suite.js
Expand Up @@ -66,7 +66,7 @@ this.Suite.prototype = new(function () {
var match = false;

var keys = Object.keys(tests).filter(function (k) {
return k !== 'topic';
return k !== 'topic' && k !== 'teardown';
});

for (var i = 0, key; i < keys.length; i++) {
Expand Down Expand Up @@ -163,7 +163,8 @@ this.Suite.prototype = new(function () {

// Now run the tests, or sub-contexts
Object.keys(ctx.tests).filter(function (k) {
return ctx.tests[k] && k !== 'topic' && !ctx.tests[k]._skip;
return ctx.tests[k] && k !== 'topic' &&
k !== 'teardown' && !ctx.tests[k]._skip;
}).forEach(function (item) {
// Create a new evaluation context,
// inheriting from the parent one.
Expand Down Expand Up @@ -201,6 +202,12 @@ this.Suite.prototype = new(function () {
}
}
});
// Teardown
topic.addListener("success", function () {
if (ctx.tests.teardown) {
ctx.tests.teardown.apply(ctx.env, ctx.topics);
}
});
if (! ctx.tests._skip) {
batch.remaining --;
}
Expand Down
20 changes: 20 additions & 0 deletions test/vows-test.js
Expand Up @@ -301,3 +301,23 @@ vows.describe("Vows with multiple batches added as optional parameters", {
}
}).export(module);

vows.describe("Vows with teardowns").addBatch({
"A context": {
topic: function () {
return { flag: true };
},
"And a vow": function (topic) {
assert.isTrue(topic.flag);
},
"And another vow": function (topic) {
assert.isTrue(topic.flag);
},
"And a final vow": function (topic) {
assert.isTrue(topic.flag);
},
teardown: function (topic) {
topic.flag = false;
}
}
}).export(module);

0 comments on commit c3ad80d

Please sign in to comment.