Skip to content

Commit

Permalink
Working through problem with assert.throws
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebayes committed Feb 19, 2011
1 parent 74a8bad commit 9d7cf1d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.textile
@@ -1,6 +1,10 @@

h1. Node Should

h3. This project is stalled because of a possible (super obscure) issue in nodejs:

<font color="red">This project is currently on hold because I can't seem to work around this issue: https://github.com/ry/node/issues#issue/693</font>. Any ideas or thoughts about what I'm doing wrong, or how to work around this issue would be welcomed.

'Node Should' is a(nother) implementation of "Shoulda":http://thoughtbot.com/community/ in JavaScript and
specifically in the "NodeJS":http://nodejs.org/ runtime environment.

Expand Down
1 change: 1 addition & 0 deletions runner.js
Expand Up @@ -9,6 +9,7 @@ require('unit/test_context')

process.on('exit', function() {
console.log('\n');
console.log('>> See test/fixtures/first.js for information about failing throws');
console.log('>> Tests Complete');
});

16 changes: 6 additions & 10 deletions src/node_should/assert.js
Expand Up @@ -241,34 +241,30 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
};

function expectedException(actual, expected) {
console.log('------------------------');
console.log(">> expectedException with actual: " + actual + " and expected: " + expected);
console.log(">> actual: " + actual + " type: " + typeof(actual));
console.log(">> expected: " + expected + " type: " + typeof(expected));
console.log(">> expected is regex?: " + (expected instanceof RegExp));
//console.log('------------------------');
//console.log(">> expectedException with actual: " + actual + " and expected: " + expected);
//console.log(">> actual: " + actual + " type: " + typeof(actual));
//console.log(">> expected: " + expected + " type: " + typeof(expected));
//console.log(">> expected is regex?: " + (expected instanceof RegExp));

if (!actual || !expected) {
return false;
}

console.log(">> passed one");
//console.log(">> passed one");

if (expected instanceof RegExp) {
return expected.test(actual);
} else if (actual instanceof expected) {
return true;
} else if (expected.call({}, actual) === true) {
return true;
} else {
console.log(">> WTF IS IT?: " + typeof(expected));
}

console.log('------------------------');
return false;
}

function _throws(shouldThrow, block, expected, message) {
console.log(">> _throws: " + shouldThrow + " block: " + block + " expected: " + expected + " message: " + message);
var actual;

if (typeof expected === 'string') {
Expand Down
3 changes: 2 additions & 1 deletion src/node_should/runner.js
Expand Up @@ -28,7 +28,8 @@ Runner.prototype.run = function(expr, path, printers, completeHandler) {

Runner.prototype._runFileContent = function(file, content, printers, completeHandler) {
var scope = this._createScope(file, printers, completeHandler);
vm.runInNewContext(content, scope, file);
var script = vm.createScript(content, file);
script.runInNewContext(scope);
}

Runner.prototype._createScope = function(file, printers, completeHandler) {
Expand Down
7 changes: 5 additions & 2 deletions test/fixtures/first.js
Expand Up @@ -11,8 +11,11 @@ context('SomeClass', function() {

should('throw exception', function() {
assert.throws(function() {
throw 'hello world';
}, /hello/);
throw new Error('hello world');
// This passes:
});
// This fails:
//}, /hello/);
});
});

4 changes: 1 addition & 3 deletions test/unit/test_runner.js
Expand Up @@ -9,14 +9,12 @@ var FakePrinter = require('fake_printer').FakePrinter;
var r = new Runner();
})();

/*
(function runnerCanLoadFiles() {
var printer = new FakePrinter();
var r = new Runner();
r.run(/first.js/, 'test/fixtures', [printer], function() {
console.log(printer.out.message);
//console.log(printer.out.message);
assert.match(/OK: 2/, printer.out.message);
});
})();
*/

0 comments on commit 9d7cf1d

Please sign in to comment.