diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index 2dea698..49a986d 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -1083,4 +1083,55 @@ describe("jasmine spec running", function () { expect(exceptionMessage).toEqual('explodes function should not have been called'); }); + it("should recover gracefully when there are errors in describe functions", function() { + var specs = []; + var superSimpleReporter = new jasmine.Reporter(); + superSimpleReporter.reportSpecResults = function(spec) { + specs.push("Spec: " + spec.getFullName()); + var results = spec.results().getItems(); + for (var i = 0; i < results.length; i++) { + var result = results[i]; + specs.push("Result: " + result); + } + }; + + try { + env.describe("outer1", function() { + env.describe("inner1", function() { + env.it("should thingy", function() { + this.expect(true).toEqual(true); + }); + + throw new Error("fake error"); + }); + + env.describe("inner2", function() { + env.it("should other thingy", function() { + this.expect(true).toEqual(true); + }); + }); + }); + } catch(e) {} + + env.describe("outer2", function() { + env.it("should xxx", function() { + this.expect(true).toEqual(true); + }); + }); + + env.addReporter(superSimpleReporter); + env.execute(); + + expect(specs).toEqual([ + 'Spec: outer1 inner1 should thingy.', + 'Result: Passed.', + 'Spec: outer1 encountered a declaration exception.', + 'Result: Error: fake error', + 'Spec: outer1 inner2 should other thingy.', + 'Result: Passed.', + 'Spec: outer2 should xxx.', + 'Result: Passed.' + ]); + }); + }); diff --git a/src/Env.js b/src/Env.js index 94606b0..e62bdff 100644 --- a/src/Env.js +++ b/src/Env.js @@ -96,10 +96,21 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) { this.currentSuite = suite; - specDefinitions.call(suite); + var declarationError = null; + try { + specDefinitions.call(suite); + } catch(e) { + declarationError = e; + } this.currentSuite = parentSuite; + if (declarationError) { + this.it("encountered a declaration exception", function() { + throw declarationError; + }); + } + return suite; }; diff --git a/src/base.js b/src/base.js index b3d914e..2948888 100755 --- a/src/base.js +++ b/src/base.js @@ -57,6 +57,10 @@ jasmine.MessageResult = function(text) { this.trace = new Error(); // todo: test better }; +jasmine.MessageResult.prototype.toString = function() { + return this.text; +}; + jasmine.ExpectationResult = function(params) { this.type = 'ExpectationResult'; this.matcherName = params.matcherName; @@ -71,6 +75,10 @@ jasmine.ExpectationResult = function(params) { this.trace = this.passed_ ? '' : new Error(this.message); }; +jasmine.ExpectationResult.prototype.toString = function () { + return this.message; +}; + jasmine.ExpectationResult.prototype.passed = function () { return this.passed_; };