From 1b02c0acf7ba3a2c90d6b9d87fe9ee147e7ba946 Mon Sep 17 00:00:00 2001 From: Matt Lyon Date: Sat, 10 Apr 2010 16:05:00 +0800 Subject: [PATCH] bugfix: only add setup vals to context once see test case, this was failing before because it was overwriting the previous context value. --- lib/vows.js | 14 +++++++++----- test/vows-test.js | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/vows.js b/lib/vows.js index 8272b41..ea206a7 100644 --- a/lib/vows.js +++ b/lib/vows.js @@ -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); @@ -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 @@ -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)); diff --git a/test/vows-test.js b/test/vows-test.js index 3582a14..9f73a7d 100644 --- a/test/vows-test.js +++ b/test/vows-test.js @@ -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()); + } } } }