From 145a2253e834f1b7cc990fecd647d007eeed2553 Mon Sep 17 00:00:00 2001 From: pivotal Date: Thu, 15 Jan 2009 14:27:39 -0800 Subject: [PATCH] dwf/rva: exception handling should now work in most cases. --- jasmine.iws | 8 ++--- lib/jasmine.js | 75 ++++++++++++++++++++++------------------------- test/bootstrap.js | 42 ++++++++++++++------------ 3 files changed, 63 insertions(+), 62 deletions(-) diff --git a/jasmine.iws b/jasmine.iws index eed4a4e1..69750ecc 100644 --- a/jasmine.iws +++ b/jasmine.iws @@ -92,7 +92,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -548,14 +548,14 @@ - + - + diff --git a/lib/jasmine.js b/lib/jasmine.js index 32621b33..51480fb7 100755 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -133,14 +133,22 @@ var queuedFunction = function(func, timeout, spec) { next: function () { spec.finish(); // default value is to be done after one function }, + safeExecute: function () { + try { + that.func.apply(spec); + } + catch (e) { + spec.results.push({passed:false, message: Jasmine.Util.formatException(e)}); + } + }, execute: function () { if (timeout > 0) { setTimeout(function () { - that.func.apply(spec); + that.safeExecute(); that.next(); }, timeout); } else { - that.func.apply(spec); + that.safeExecute(); that.next(); } } @@ -252,22 +260,9 @@ var it = function (description, func) { that.finished = true; }, - safeExecute: function(queuedFunc) { - try { - queuedFunc.execute(); - } - catch (e) { - that.results.push({ - passed: false, - message: Jasmine.Util.formatException(e) - }); - queuedFunc.next(); - } - }, - execute: function () { if (that.queue[0]) { - that.safeExecute(that.queue[0]) + that.queue[0].execute(); } else { that.finish(); @@ -282,7 +277,7 @@ var it = function (description, func) { if (that.queue.length > 1) { var previousFunction = that.queue[that.queue.length - 2]; previousFunction.next = function () { - that.safeExecute(currentFunction); + currentFunction.execute(); } } @@ -395,32 +390,32 @@ Jasmine.Reporters.reporter = function (callbacks) { Jasmine.Util = { formatException: function(e) { - // if (typeof e === 'String') { - // return e; - // } - var lineNumber; - if (e.line) { - lineNumber = e.line; - } - else if (e.lineNumber) { - lineNumber = e.lineNumber; - } + // if (typeof e === 'String') { + // return e; + // } + var lineNumber; + if (e.line) { + lineNumber = e.line; + } + else if (e.lineNumber) { + lineNumber = e.lineNumber; + } - var file; + var file; - if (e.sourceURL) { - file = e.sourceURL; - } - else if (e.fileName) { - file = e.fileName; - } + if (e.sourceURL) { + file = e.sourceURL; + } + else if (e.fileName) { + file = e.fileName; + } - var message = e.name + ': ' + e.message; - if (file && lineNumber) { - message += ' in ' + file +' (line ' + lineNumber + ')'; - } + var message = e.name + ': ' + e.message; + if (file && lineNumber) { + message += ' in ' + file + ' (line ' + lineNumber + ')'; + } - return message; - } + return message; + } } \ No newline at end of file diff --git a/test/bootstrap.js b/test/bootstrap.js index 73b11249..2bd7f888 100755 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -858,29 +858,29 @@ var testHandlesExceptions = function () { }); }); -// it('should be another test that fails because it throws an exception after a wait', function() { - // runs(function () { - // var foo = 'foo'; - // }); - // waits(250); - // runs(function () { - // fakeObject2.fakeMethod2(); - // }); - // }); - // - // it('should be a passing test that runs after exceptions are thrown from a async test', function() { - // runs(function () { - // this.expects_that(true).should_equal(true); - // }); - // }); + it('should be another test that fails because it throws an exception after a wait', function() { + runs(function () { + var foo = 'foo'; + }); + waits(250); + runs(function () { + fakeObject3.fakeMethod(); + }); + }); + + it('should be a passing test that runs after exceptions are thrown from a async test', function() { + runs(function () { + this.expects_that(true).should_equal(true); + }); + }); }); runner.execute(); setTimeout(function() { - reporter.test((runner.suites[0].specResults.length === 3), - 'Should have found 3 spec results, got ' + runner.suites[0].specResults.length); + reporter.test((runner.suites[0].specResults.length === 5), + 'Should have found 4 spec results, got ' + runner.suites[0].specResults.length); reporter.test((runner.suites[0].specs[0].expectationResults[0].passed === false), 'First test should have failed, got passed'); @@ -892,13 +892,19 @@ var testHandlesExceptions = function () { 'Second test should have a failing first result, got passed'); reporter.test((typeof runner.suites[0].specs[1].expectationResults[0].message.search(/fakeObject2/) !== -1), - 'First test should have contained /fakeObject/, got ' + runner.suites[0].specs[1].expectationResults[0].message); + 'Second test should have contained /fakeObject2/, got ' + runner.suites[0].specs[1].expectationResults[0].message); reporter.test((runner.suites[0].specs[1].expectationResults[1].passed === true), 'Second expectation in second test should have still passed'); reporter.test((runner.suites[0].specs[2].expectationResults[0].passed === true), 'Third test should have passed, got failed'); + + reporter.test((runner.suites[0].specs[3].expectationResults[0].passed === false), + 'Fourth test should have a failing first result, got passed'); + + reporter.test((typeof runner.suites[0].specs[3].expectationResults[0].message.search(/fakeObject3/) !== -1), + 'Fourth test should have contained /fakeObject3/, got ' + runner.suites[0].specs[3].expectationResults[0].message); }, 2000); }