diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index 2de2dc2e..6ed4604a 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -408,17 +408,23 @@ describe("jasmine spec running", function () { env.execute(); }); - it('runs fits in fdescribes twice', function(done){ + it('runs fits and fdescribes in fdescribes only once', function(done){ var actions = []; env.fdescribe('focused suite', function() { env.fit('focused spec', function() { actions.push('focused spec') }); + + env.fdescribe('inner focused suite', function() { + env.it('inner spec', function() { + actions.push('unfocused spec'); + }); + }); }); var assertions = function() { - var expected = ['focused spec', 'focused spec']; + var expected = ['focused spec', 'unfocused spec']; expect(actions).toEqual(expected); done(); }; diff --git a/src/core/Env.js b/src/core/Env.js index 97c3fa62..c16401d2 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -295,11 +295,44 @@ getJasmineRequireObj().Env = function(j$) { }; this.fdescribe = function(description, specDefinitions) { - var suite = this.describe(description, specDefinitions); - focusedRunnables.push(suite.id); + var suite = suiteFactory(description); + suite.isFocused = true; + + var parentSuite = currentDeclarationSuite; + parentSuite.addChild(suite); + currentDeclarationSuite = suite; + + var declarationError = null; + try { + specDefinitions.call(suite); + } catch (e) { + declarationError = e; + } + + if (declarationError) { + this.it('encountered a declaration exception', function() { + throw declarationError; + }); + } + + currentDeclarationSuite = parentSuite; + if (!hasFocusedAncestor(parentSuite)) { + focusedRunnables.push(suite.id); + } return suite; }; + function hasFocusedAncestor(suite) { + while (suite) { + if (suite.isFocused) { + return true; + } + suite = suite.parentSuite; + } + + return false; + } + var runnablesExplictlySet = false; var runnablesExplictlySetGetter = function(){ @@ -361,7 +394,11 @@ getJasmineRequireObj().Env = function(j$) { var focusedRunnables = []; this.fit = function(description, fn ){ var spec = this.it(description, fn); - focusedRunnables.push(spec.id); + + if (!hasFocusedAncestor(currentDeclarationSuite)) { + focusedRunnables.push(spec.id); + } + return spec; };