Skip to content

Commit fa51949

Browse files
author
cloudhead
committed
allow nested contexts with no topics
1 parent 0b891d6 commit fa51949

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/vows.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,21 @@ vows.tell = function (subject, tests) {
274274
// If it encounters a `topic` function, it waits for the returned
275275
// promise to emit (the topic), at which point it runs the functions under it,
276276
// passing the topic as an argument.
277-
(function run(ctx) {
277+
(function run(ctx, lastTopic) {
278278
var ctxAdded = false;
279279

280-
if ('topic' in ctx.tests) {
281-
280+
topic = lastTopic = ('topic' in ctx.tests) ? ctx.tests.topic
281+
: lastTopic;
282+
if (topic) {
282283
// Topic isn't a function, wrap it into one.
283-
if (typeof(ctx.tests.topic) !== 'function') {
284-
ctx.tests.topic = (function (topic) {
284+
if (typeof(topic) !== 'function') {
285+
topic = (function (topic) {
285286
return function () { return topic };
286-
})(ctx.tests.topic);
287+
})(topic);
287288
}
288289

289290
// Run the topic, passing the previous context topics
290-
topic = ctx.tests.topic.apply(ctx.env, ctx.topics);
291+
topic = topic.apply(ctx.env, ctx.topics);
291292

292293
// If the topic doesn't return an event emitter (such as a promise),
293294
// we create it ourselves, and emit the value on the next tick.
@@ -334,11 +335,11 @@ vows.tell = function (subject, tests) {
334335
if (topic) {
335336
topic.addListener("success", function (vow, ctx) {
336337
return function (val) {
337-
return run(new(Context)(vow, ctx, env));
338+
return run(new(Context)(vow, ctx, env), lastTopic);
338339
};
339340
}(vow, ctx));
340341
} else {
341-
run(new(Context)(vow, ctx, env));
342+
run(new(Context)(vow, ctx, env), lastTopic);
342343
}
343344
}
344345
});

test/vows-test.js

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ vows.describe("Vows", {
9797
}
9898
}
9999
},
100+
"Nested contexts with no topics": {
101+
topic: 45,
102+
"should": {
103+
"pass": {
104+
"the value down": function (topic) {
105+
assert.equal(topic, 45);
106+
}
107+
}
108+
}
109+
},
100110
"Non-promise return value": {
101111
topic: function () { return 1 },
102112
"should be converted to a promise": function (val) {

0 commit comments

Comments
 (0)