Run before,afterAlls as 'eachs' when specifying runnablesToRun

- Fix bug where beforeAlls were being mutated in Suite#execute
- When Env.execute() receives a list of runnables, beforeAlls and
  afterAlls are collected as beforeEachs and afterEachs. This allows
  runnables to be specified in any order, regardless of if any of them
  have before/afterAlls.
- Spec constructor takes a single function that returns both before and
  afters, instead of two functions. This breaks the current interface
  for constructing a Spec.

[#73742528]
This commit is contained in:
Greg Cobb and Tim Jarratt
2014-08-28 11:21:41 -07:00
committed by Greg Cobb and Tim Jarratt
parent 61bf9ac7d7
commit b984ff2fa6
6 changed files with 65 additions and 27 deletions

View File

@@ -101,25 +101,23 @@ getJasmineRequireObj().Env = function(j$) {
delete runnableResources[id];
};
var beforeFns = function(suite) {
var beforeAndAfterFns = function(suite, runnablesExplictlySet) {
return function() {
var befores = [];
while(suite) {
befores = befores.concat(suite.beforeFns);
suite = suite.parentSuite;
}
return befores.reverse();
};
};
var afterFns = function(suite) {
return function() {
var afters = [];
while(suite) {
if (runnablesExplictlySet()) {
befores = befores.concat(suite.beforeAllFns);
afters = afters.concat(suite.afterAllFns);
}
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite;
}
return afters;
return {
befores: befores.reverse(),
afters: afters
};
};
};
@@ -194,6 +192,9 @@ getJasmineRequireObj().Env = function(j$) {
};
this.execute = function(runnablesToRun) {
if(runnablesToRun) {
runnablesExplictlySet = true;
}
runnablesToRun = runnablesToRun || [topSuite.id];
var allFns = [];
@@ -284,13 +285,17 @@ getJasmineRequireObj().Env = function(j$) {
return suite;
};
var runnablesExplictlySet = false;
var runnablesExplictlySetGetter = function(){
return runnablesExplictlySet;
};
var specFactory = function(description, fn, suite) {
totalSpecsDefined++;
var spec = new j$.Spec({
id: getNextSpecId(),
beforeFns: beforeFns(suite),
afterFns: afterFns(suite),
beforeAndAfterFns: beforeAndAfterFns(suite, runnablesExplictlySetGetter),
expectationFactory: expectationFactory,
exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback,