From b02aa9840aaa4fb8314a7eb79de1079d9034aa58 Mon Sep 17 00:00:00 2001 From: "Davis W. Frank" Date: Sun, 17 Apr 2011 21:44:41 -0700 Subject: [PATCH] fixed bad merge of gvanhove's describe exception fix --- spec/suites/ExceptionsSpec.js | 46 ++++++++++++++++++++++++++++++++-- spec/suites/SpecRunningSpec.js | 21 ++++++++++------ src/Env.js | 4 +-- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/spec/suites/ExceptionsSpec.js b/spec/suites/ExceptionsSpec.js index 2b75a64..fcd51ee 100644 --- a/spec/suites/ExceptionsSpec.js +++ b/spec/suites/ExceptionsSpec.js @@ -3,7 +3,7 @@ describe('Exceptions:', function() { beforeEach(function() { env = new jasmine.Env(); - env.updateInterval = 0; + env.updateInterval = 0; }); it('jasmine.formatException formats Firefox exception messages as expected', function() { @@ -101,7 +101,49 @@ describe('Exceptions:', function() { expect(blockResults[0].message).toMatch(/fake error 3/); expect(specResults[4].passed()).toEqual(true); - }); + + it("should handle exceptions thrown directly in top-level describe blocks and continue", function () { + var suite = env.describe("a top level describe block that throws an exception", function () { + env.it("is a test that should pass", function () { + this.expect(true).toEqual(true); + }); + + throw new Error("top level error"); + }); + + suite.execute(); + var suiteResults = suite.results(); + var specResults = suiteResults.getItems(); + + expect(suiteResults.passed()).toEqual(false); + expect(specResults.length).toEqual(2); + + expect(specResults[1].description).toMatch(/encountered a declaration exception/); + }); + + it("should handle exceptions thrown directly in nested describe blocks and continue", function () { + var suite = env.describe("a top level describe", function () { + env.describe("a mid-level describe that throws an exception", function () { + env.it("is a test that should pass", function () { + this.expect(true).toEqual(true); + }); + + throw new Error("a mid-level error"); + }); + }); + + suite.execute(); + var suiteResults = suite.results(); + var specResults = suiteResults.getItems(); + + expect(suiteResults.passed()).toEqual(false); + expect(specResults.length).toEqual(1); + + var nestedSpecResults = specResults[0].getItems(); + + expect(nestedSpecResults.length).toEqual(2); + expect(nestedSpecResults[1].description).toMatch(/encountered a declaration exception/); + }); }); \ No newline at end of file diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index 706449e..f5ce298 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -1225,6 +1225,9 @@ describe("jasmine spec running", function () { this.expect(true).toEqual(true); }); }); + + throw new Error("fake error"); + }); } catch(e) { } @@ -1240,14 +1243,16 @@ describe("jasmine spec running", function () { expect(specs.join('')).toMatch(new RegExp( '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.' - )); + 'Result: Passed.' + + 'Spec: outer1 inner1 encountered a declaration exception.' + + 'Result: Error: fake error.*' + + 'Spec: outer1 inner2 should other thingy.' + + 'Result: Passed.' + + 'Spec: outer1 encountered a declaration exception.' + + 'Result: Error: fake error.*' + + 'Spec: outer2 should xxx.' + + 'Result: Passed.' + )); }); }); diff --git a/src/Env.js b/src/Env.js index 07a7a42..f469a2e 100644 --- a/src/Env.js +++ b/src/Env.js @@ -104,14 +104,14 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) { declarationError = e; } - this.currentSuite = parentSuite; - if (declarationError) { this.it("encountered a declaration exception", function() { throw declarationError; }); } + this.currentSuite = parentSuite; + return suite; };