diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index 49a986d..67f5229 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -861,7 +861,7 @@ describe("jasmine spec running", function () { expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass"); }); - it("testNestedDescribes", function() { + it("should permit nested describes", function() { var actions = []; env.beforeEach(function () { @@ -953,6 +953,63 @@ describe("jasmine spec running", function () { expect(actions).toEqual(expected); }); + it("should run multiple befores and afters in the order they are declared", function() { + var actions = []; + + env.beforeEach(function () { + actions.push('runner beforeEach1'); + }); + + env.afterEach(function () { + actions.push('runner afterEach1'); + }); + + env.beforeEach(function () { + actions.push('runner beforeEach2'); + }); + + env.afterEach(function () { + actions.push('runner afterEach2'); + }); + + env.describe('Something', function() { + env.beforeEach(function() { + actions.push('beforeEach1'); + }); + + env.afterEach(function() { + actions.push('afterEach1'); + }); + + env.beforeEach(function() { + actions.push('beforeEach2'); + }); + + env.afterEach(function() { + actions.push('afterEach2'); + }); + + env.it('does it 1', function() { + actions.push('outer it 1'); + }); + }); + + env.execute(); + + var expected = [ + "runner beforeEach1", + "runner beforeEach2", + "beforeEach1", + "beforeEach2", + "outer it 1", + "afterEach2", + "afterEach1", + "runner afterEach2", + "runner afterEach1" + ]; + expect(actions).toEqual(expected); + }); + it("builds up nested names", function() { var nestedSpec; env.describe('Test Subject', function() { diff --git a/src/Runner.js b/src/Runner.js index ee850d7..dc8c0be 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -25,12 +25,12 @@ jasmine.Runner.prototype.execute = function() { jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { beforeEachFunction.typeName = 'beforeEach'; - this.before_.push(beforeEachFunction); + this.before_.unshift(beforeEachFunction); }; jasmine.Runner.prototype.afterEach = function(afterEachFunction) { afterEachFunction.typeName = 'afterEach'; - this.after_.push(afterEachFunction); + this.after_.unshift(afterEachFunction); }; diff --git a/src/Suite.js b/src/Suite.js index 6d7698a..4ea1de3 100644 --- a/src/Suite.js +++ b/src/Suite.js @@ -37,12 +37,12 @@ jasmine.Suite.prototype.finish = function(onComplete) { jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { beforeEachFunction.typeName = 'beforeEach'; - this.before_.push(beforeEachFunction); + this.before_.unshift(beforeEachFunction); }; jasmine.Suite.prototype.afterEach = function(afterEachFunction) { afterEachFunction.typeName = 'afterEach'; - this.after_.push(afterEachFunction); + this.after_.unshift(afterEachFunction); }; jasmine.Suite.prototype.results = function() {