Skip to content

Commit

Permalink
bugfix: only add setup vals to context once
Browse files Browse the repository at this point in the history
see test case, this was failing before because it was overwriting the
previous context value.
  • Loading branch information
Matt Lyon authored and Alexis Sellier committed Apr 16, 2010
1 parent d83b203 commit 1b02c0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ vows.tell = function (topic, tests) {
// functions have access to all the previous context topics in their
// arguments list.
// It is defined and invoked at the same time.
// If it encouters a `setup` function, it waits for the returned
// If it encounters a `setup` function, it waits for the returned
// promise to emit (the topic), at which point it runs the functions under it,
// passing the topic as an argument.
(function run(ctx) {
var ctxAdded = false;
if (typeof(ctx.tests["setup"]) === 'function') {
// Run the setup, passing the previous context topics
setup = ctx.tests.setup.apply(this, ctx.topics);
Expand All @@ -237,6 +238,13 @@ vows.tell = function (topic, tests) {
return function () { emitter.emit("success", val) };
}(setup)); setup = emitter;
}

setup.addListener('success', function (val) {
// Once the setup fires, add the return value
// to the beginning of the topics list, so it
// becomes the first argument for the next setup.
ctx.topics.unshift(val);
});
} else { setup = null }

// Now run the tests, or sub-contexts
Expand All @@ -260,10 +268,6 @@ vows.tell = function (topic, tests) {
if (setup) {
setup.addListener("success", function (vow, ctx) {
return function (val) {
// Once the setup fires, add the return value
// to the beginning of the topics list, so it
// becomes the first argument for the next setup.
ctx.topics.unshift(val);
return run(new(Context)(vow, ctx));
};
}(vow, ctx));
Expand Down
8 changes: 8 additions & 0 deletions test/vows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ vows.tell("Vows", {
"the parent topics": function (topics) {
assert.equal(topics.join(), [4, 3, 2, 1].join());
}
},

"from": {
setup: function (c, b, a) { return promiser([4, c, b, a])() },

"the parent topics": function(topics) {
assert.equal(topics.join(), [4, 3, 2, 1].join());
}
}
}
}
Expand Down

0 comments on commit 1b02c0a

Please sign in to comment.