Skip to content

Commit 8a03c2a

Browse files
author
cloudhead
committed
'setup' is now called 'topic'
1 parent a7b5857 commit 8a03c2a

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

lib/vows.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ vows.options = {
199199
// Run all vows/tests.
200200
// It can take either a function as `tests`,
201201
// or an object literal.
202-
vows.tell = function (topic, tests) {
202+
vows.tell = function (subject, tests) {
203203
this.options.Emitter.prototype.addVow = addVow;
204204
this.tests = tests;
205205
this.remaining = 0;
@@ -222,14 +222,14 @@ vows.tell = function (topic, tests) {
222222

223223
// We run the tests asynchronously, for added flexibility
224224
process.nextTick(function () {
225-
var setup, vow, env;
225+
var topic, vow, env;
226226

227-
if (typeof(topic) === 'string' && tests) {
227+
if (typeof(subject) === 'string' && tests) {
228228
if (!vows.options.brief) {
229229
puts('\n' + stylize(topic, 'underline') + '\n');
230230
}
231-
} else if (topic instanceof Object || topic instanceof Function) {
232-
vows.tests = topic;
231+
} else if (subject instanceof Object || subject instanceof Function) {
232+
vows.tests = subject;
233233
} else { throw "tell() takes a topic and an Object" }
234234

235235
start = new(Date);
@@ -257,49 +257,49 @@ vows.tell = function (topic, tests) {
257257
})(vows.tests);
258258

259259
// The test runner, it calls itself recursively, passing the
260-
// previous context to the inner contexts. This is so the `setup`
260+
// previous context to the inner contexts. This is so the `topic`
261261
// functions have access to all the previous context topics in their
262262
// arguments list.
263263
// It is defined and invoked at the same time.
264-
// If it encounters a `setup` function, it waits for the returned
264+
// If it encounters a `topic` function, it waits for the returned
265265
// promise to emit (the topic), at which point it runs the functions under it,
266266
// passing the topic as an argument.
267267
(function run(ctx) {
268268
var ctxAdded = false;
269269

270-
if ('setup' in ctx.tests) {
270+
if ('topic' in ctx.tests) {
271271

272-
// Setup isn't a function, wrap it into one.
273-
if (typeof(ctx.tests.setup) !== 'function') {
274-
ctx.tests.setup = (function (topic) {
272+
// Topic isn't a function, wrap it into one.
273+
if (typeof(ctx.tests.topic) !== 'function') {
274+
ctx.tests.topic = (function (topic) {
275275
return function () { return topic };
276-
})(ctx.tests.setup);
276+
})(ctx.tests.topic);
277277
}
278278

279-
// Run the setup, passing the previous context topics
280-
setup = ctx.tests.setup.apply(ctx.env, ctx.topics);
279+
// Run the topic, passing the previous context topics
280+
topic = ctx.tests.topic.apply(ctx.env, ctx.topics);
281281

282-
// If the setup doesn't return an event emitter (such as a promise),
282+
// If the topic doesn't return an event emitter (such as a promise),
283283
// we create it ourselves, and emit the value on the next tick.
284-
if (! (setup instanceof vows.options.Emitter)) {
284+
if (! (topic instanceof vows.options.Emitter)) {
285285
var emitter = new(vows.options.Emitter);
286286

287287
process.nextTick(function (val) {
288288
return function () { emitter.emit("success", val) };
289-
}(setup)); setup = emitter;
289+
}(topic)); topic = emitter;
290290
}
291291

292-
setup.addListener('success', function (val) {
293-
// Once the setup fires, add the return value
292+
topic.addListener('success', function (val) {
293+
// Once the topic fires, add the return value
294294
// to the beginning of the topics list, so it
295-
// becomes the first argument for the next setup.
295+
// becomes the first argument for the next topic.
296296
ctx.topics.unshift(val);
297297
});
298-
} else { setup = null }
298+
} else { topic = null }
299299

300300
// Now run the tests, or sub-contexts
301301
Object.keys(ctx.tests).filter(function (k) {
302-
return ctx.tests[k] && k !== 'setup';
302+
return ctx.tests[k] && k !== 'topic';
303303
}).forEach(function (item) {
304304
// Holds the current test or context
305305
vow = Object.create({
@@ -311,18 +311,18 @@ vows.tell = function (topic, tests) {
311311
env = Object.create(ctx.env);
312312

313313
// If we encounter a function, add it to the callbacks
314-
// of the `setup` function, so it'll get called once the
315-
// setup fires.
314+
// of the `topic` function, so it'll get called once the
315+
// topic fires.
316316
// If we encounter an object literal, we recurse, sending it
317317
// our current context.
318318
if (typeof(vow.callback) === 'function') {
319-
setup.addVow(vow);
319+
topic.addVow(vow);
320320
} else if (typeof(vow.callback) === 'object' && ! Array.isArray(vow.callback)) {
321321
// If there's a setup stage, we have to wait for it to fire,
322322
// before calling the inner context. Else, just run the inner context
323323
// synchronously.
324-
if (setup) {
325-
setup.addListener("success", function (vow, ctx) {
324+
if (topic) {
325+
topic.addListener("success", function (vow, ctx) {
326326
return function (val) {
327327
return run(new(Context)(vow, ctx, env));
328328
};

test/vows-test.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ var promiser = function (val) {
2121
}
2222
};
2323

24-
vows.tell("Vows", {
24+
vows.describe("Vows", {
2525
"A context": {
26-
setup: promiser("hello world"),
26+
topic: promiser("hello world"),
2727

2828
"testing equality": function (it) {
2929
assert.equal(it, "hello world");
@@ -45,7 +45,7 @@ vows.tell("Vows", {
4545
assert.isEmpty("");
4646
},
4747
"with a nested context": {
48-
setup: function (parent) {
48+
topic: function (parent) {
4949
this.state = 42;
5050
return promiser(parent)();
5151
},
@@ -56,7 +56,7 @@ vows.tell("Vows", {
5656
assert.equal(this.state, 42);
5757
},
5858
"a sub context": {
59-
setup: function () {
59+
topic: function () {
6060
return this.state;
6161
},
6262
"has access to the parent environment": function (r) {
@@ -71,24 +71,24 @@ vows.tell("Vows", {
7171
}
7272
},
7373
"Nested contexts": {
74-
setup: promiser(1),
74+
topic: promiser(1),
7575

7676
"have": {
77-
setup: function (a) { return promiser(2)() },
77+
topic: function (a) { return promiser(2)() },
7878

7979
"access": {
80-
setup: function (b, a) { return promiser(3)() },
80+
topic: function (b, a) { return promiser(3)() },
8181

8282
"to": {
83-
setup: function (c, b, a) { return promiser([4, c, b, a])() },
83+
topic: function (c, b, a) { return promiser([4, c, b, a])() },
8484

8585
"the parent topics": function (topics) {
8686
assert.equal(topics.join(), [4, 3, 2, 1].join());
8787
}
8888
},
8989

9090
"from": {
91-
setup: function (c, b, a) { return promiser([4, c, b, a])() },
91+
topic: function (c, b, a) { return promiser([4, c, b, a])() },
9292

9393
"the parent topics": function(topics) {
9494
assert.equal(topics.join(), [4, 3, 2, 1].join());
@@ -98,27 +98,27 @@ vows.tell("Vows", {
9898
}
9999
},
100100
"Non-promise return value": {
101-
setup: function () { return 1 },
101+
topic: function () { return 1 },
102102
"should be converted to a promise": function (val) {
103103
assert.equal(val, 1);
104104
}
105105
},
106106
"A 'prepared' interface": {
107107
"with a wrapped function": {
108-
setup: function () { return api.get(42) },
108+
topic: function () { return api.get(42) },
109109
"should work as expected": function (val) {
110110
assert.equal(val, 42);
111111
}
112112
},
113113
"with a non-wrapped function": {
114-
setup: function () { return api.version() },
114+
topic: function () { return api.version() },
115115
"should work as expected": function (val) {
116116
assert.equal(val, '1.0');
117117
}
118118
}
119119
},
120120
"Non-functions as subjects": {
121-
setup: 45,
121+
topic: 45,
122122

123123
"should work as expected": function (subject) {
124124
assert.equal(subject, 45);

0 commit comments

Comments
 (0)