dwf/rva: exception handling should now work in most cases.

This commit is contained in:
pivotal 2009-01-15 14:27:39 -08:00
parent c94496c9fe
commit 145a2253e8
3 changed files with 63 additions and 62 deletions

View File

@ -92,7 +92,7 @@
<file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="893" column="101" selection-start="27681" selection-end="27681" vertical-scroll-proportion="0.6620553"> <state line="861" column="1" selection-start="26398" selection-end="26398" vertical-scroll-proportion="0.6571146">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -101,7 +101,7 @@
<file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true"> <file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="246" column="7" selection-start="5573" selection-end="5573" vertical-scroll-proportion="0.4935065"> <state line="265" column="7" selection-start="5960" selection-end="5960" vertical-scroll-proportion="0.13286713">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -548,14 +548,14 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="893" column="101" selection-start="27681" selection-end="27681" vertical-scroll-proportion="0.6620553"> <state line="861" column="1" selection-start="26398" selection-end="26398" vertical-scroll-proportion="0.6571146">
<folding /> <folding />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="246" column="7" selection-start="5573" selection-end="5573" vertical-scroll-proportion="0.4935065"> <state line="265" column="7" selection-start="5960" selection-end="5960" vertical-scroll-proportion="0.13286713">
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@ -133,14 +133,22 @@ var queuedFunction = function(func, timeout, spec) {
next: function () { next: function () {
spec.finish(); // default value is to be done after one 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 () { execute: function () {
if (timeout > 0) { if (timeout > 0) {
setTimeout(function () { setTimeout(function () {
that.func.apply(spec); that.safeExecute();
that.next(); that.next();
}, timeout); }, timeout);
} else { } else {
that.func.apply(spec); that.safeExecute();
that.next(); that.next();
} }
} }
@ -252,22 +260,9 @@ var it = function (description, func) {
that.finished = true; 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 () { execute: function () {
if (that.queue[0]) { if (that.queue[0]) {
that.safeExecute(that.queue[0]) that.queue[0].execute();
} }
else { else {
that.finish(); that.finish();
@ -282,7 +277,7 @@ var it = function (description, func) {
if (that.queue.length > 1) { if (that.queue.length > 1) {
var previousFunction = that.queue[that.queue.length - 2]; var previousFunction = that.queue[that.queue.length - 2];
previousFunction.next = function () { previousFunction.next = function () {
that.safeExecute(currentFunction); currentFunction.execute();
} }
} }
@ -395,32 +390,32 @@ Jasmine.Reporters.reporter = function (callbacks) {
Jasmine.Util = { Jasmine.Util = {
formatException: function(e) { formatException: function(e) {
// if (typeof e === 'String') { // if (typeof e === 'String') {
// return e; // return e;
// } // }
var lineNumber; var lineNumber;
if (e.line) { if (e.line) {
lineNumber = e.line; lineNumber = e.line;
} }
else if (e.lineNumber) { else if (e.lineNumber) {
lineNumber = e.lineNumber; lineNumber = e.lineNumber;
} }
var file; var file;
if (e.sourceURL) { if (e.sourceURL) {
file = e.sourceURL; file = e.sourceURL;
} }
else if (e.fileName) { else if (e.fileName) {
file = e.fileName; file = e.fileName;
} }
var message = e.name + ': ' + e.message; var message = e.name + ': ' + e.message;
if (file && lineNumber) { if (file && lineNumber) {
message += ' in ' + file +' (line ' + lineNumber + ')'; message += ' in ' + file + ' (line ' + lineNumber + ')';
} }
return message; return message;
} }
} }

42
test/bootstrap.js vendored
View File

@ -858,29 +858,29 @@ var testHandlesExceptions = function () {
}); });
}); });
// it('should be another test that fails because it throws an exception after a wait', function() { it('should be another test that fails because it throws an exception after a wait', function() {
// runs(function () { runs(function () {
// var foo = 'foo'; var foo = 'foo';
// }); });
// waits(250); waits(250);
// runs(function () { runs(function () {
// fakeObject2.fakeMethod2(); fakeObject3.fakeMethod();
// }); });
// }); });
//
// it('should be a passing test that runs after exceptions are thrown from a async test', function() { it('should be a passing test that runs after exceptions are thrown from a async test', function() {
// runs(function () { runs(function () {
// this.expects_that(true).should_equal(true); this.expects_that(true).should_equal(true);
// }); });
// }); });
}); });
runner.execute(); runner.execute();
setTimeout(function() { setTimeout(function() {
reporter.test((runner.suites[0].specResults.length === 3), reporter.test((runner.suites[0].specResults.length === 5),
'Should have found 3 spec results, got ' + runner.suites[0].specResults.length); 'Should have found 4 spec results, got ' + runner.suites[0].specResults.length);
reporter.test((runner.suites[0].specs[0].expectationResults[0].passed === false), reporter.test((runner.suites[0].specs[0].expectationResults[0].passed === false),
'First test should have failed, got passed'); 'First test should have failed, got passed');
@ -892,13 +892,19 @@ var testHandlesExceptions = function () {
'Second test should have a failing first result, got passed'); 'Second test should have a failing first result, got passed');
reporter.test((typeof runner.suites[0].specs[1].expectationResults[0].message.search(/fakeObject2/) !== -1), 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), reporter.test((runner.suites[0].specs[1].expectationResults[1].passed === true),
'Second expectation in second test should have still passed'); 'Second expectation in second test should have still passed');
reporter.test((runner.suites[0].specs[2].expectationResults[0].passed === true), reporter.test((runner.suites[0].specs[2].expectationResults[0].passed === true),
'Third test should have passed, got failed'); '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); }, 2000);
} }