Skip to content

Commit

Permalink
fix vow context when global
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Feb 21, 2011
1 parent f700eed commit 3291d77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function addVow(vow) {
// Run the test, and try to catch `AssertionError`s and other exceptions;
// increment counters accordingly.
try {
vow.callback.apply(ctx || vow.binding || null, args);
vow.callback.apply(ctx === global || !ctx ? vow.binding : ctx, args);
output('honored');
} catch (e) {
if (e.name && e.name.match(/AssertionError/)) {
Expand Down
14 changes: 13 additions & 1 deletion test/vows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,19 @@ vows.describe("Vows").addBatch({
topic: function () {
this.callback.call({ boo: true }, null, 'hello');
},
"should work the same as returning a value": function (res) {
"should give access to the user context": function (res) {
assert.isTrue(this.boo);
}
},
"passing this.callback to a function": {
topic: function () {
this.boo = true;
var async = function (callback) {
callback(null);
};
async(this.callback);
},
"should give access to the topic context": function (e, t, tt) {
assert.isTrue(this.boo);
}
},
Expand Down

0 comments on commit 3291d77

Please sign in to comment.