Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Callbacks tests have this passed through and add test context as extr…

…a argument
  • Loading branch information...
commit 6e636313c60c0aee91bd8ac92e9f0fffdee0057a 1 parent 349437b
@leei authored
Showing with 15 additions and 4 deletions.
  1. +2 −3 lib/vows.js
  2. +7 −1 lib/vows/context.js
  3. +6 −0 test/vows-test.js
View
5 lib/vows.js
@@ -83,8 +83,6 @@ function addVow(vow) {
});
function runTest(args) {
- var topic, status;
-
if (vow.callback instanceof String) {
return output('pending');
}
@@ -92,7 +90,8 @@ function addVow(vow) {
// Run the test, and try to catch `AssertionError`s and other exceptions;
// increment counters accordingly.
try {
- vow.callback.apply(vow.binding || null, args);
+ var env = vow.binding;
+ vow.callback.apply((env && env.binding) || vow.binding || null, args);
output('honored');
} catch (e) {
if (e.name && e.name.match(/AssertionError/)) {
View
8 lib/vows/context.js
@@ -1,4 +1,4 @@
-
+var sys = require('sys');
this.Context = function (vow, ctx, env) {
var that = this;
@@ -9,7 +9,13 @@ this.Context = function (vow, ctx, env) {
this.env.context = this;
this.env.callback = function (/* arguments */) {
+ var target = this;
var args = Array.prototype.slice.call(arguments);
+ // Add context as extra argument
+ args.push(that);
+ // Attach a binding to the env...
+ env.binding = target;
+
var emit = (function (args) {
//
// Convert callback-style results into events.
View
6 test/vows-test.js
@@ -91,6 +91,12 @@ vows.describe("Vows").addBatch({
},
'after a successful `fs.read`': function (data) {
assert.match (data, /after a successful `fs.read`/);
+ },
+ 'should set this to the target of fs.read callback': function(data) {
+ assert.deepEqual(this, {});
+ },
+ 'should pass context as extra parameter': function(_, _, _, context) {
+ assert.equal(context.name, 'after a successful `fs.open`');
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.