Factor out some common logic between fdesc and desc

This commit is contained in:
Greg Cobb and Tim Jarratt
2014-08-29 09:25:41 -07:00
parent 08a35d134d
commit 6b857d11ce

View File

@@ -265,26 +265,7 @@ getJasmineRequireObj().Env = function(j$) {
this.describe = function(description, specDefinitions) { this.describe = function(description, specDefinitions) {
var suite = suiteFactory(description); var suite = suiteFactory(description);
addSpecsToSuite(suite, specDefinitions);
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;
return suite; return suite;
}; };
@@ -297,7 +278,15 @@ getJasmineRequireObj().Env = function(j$) {
this.fdescribe = function(description, specDefinitions) { this.fdescribe = function(description, specDefinitions) {
var suite = suiteFactory(description); var suite = suiteFactory(description);
suite.isFocused = true; suite.isFocused = true;
addSpecsToSuite(suite, specDefinitions);
if (!hasFocusedAncestor(suite.parentSuite)) {
focusedRunnables.push(suite.id);
}
return suite;
};
function addSpecsToSuite(suite, specDefinitions) {
var parentSuite = currentDeclarationSuite; var parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite); parentSuite.addChild(suite);
currentDeclarationSuite = suite; currentDeclarationSuite = suite;
@@ -310,17 +299,13 @@ getJasmineRequireObj().Env = function(j$) {
} }
if (declarationError) { if (declarationError) {
this.it('encountered a declaration exception', function() { self.it('encountered a declaration exception', function() {
throw declarationError; throw declarationError;
}); });
} }
currentDeclarationSuite = parentSuite; currentDeclarationSuite = parentSuite;
if (!hasFocusedAncestor(parentSuite)) { }
focusedRunnables.push(suite.id);
}
return suite;
};
function hasFocusedAncestor(suite) { function hasFocusedAncestor(suite) {
while (suite) { while (suite) {