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,

View File

@@ -5,8 +5,7 @@ getJasmineRequireObj().Spec = function(j$) {
this.id = attrs.id;
this.description = attrs.description || '';
this.queueableFn = attrs.queueableFn;
this.beforeFns = attrs.beforeFns || function() { return []; };
this.afterFns = attrs.afterFns || function() { return []; };
this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; };
this.userContext = attrs.userContext || function() { return {}; };
this.onStart = attrs.onStart || function() {};
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
@@ -48,7 +47,8 @@ getJasmineRequireObj().Spec = function(j$) {
return;
}
var allFns = this.beforeFns().concat(this.queueableFn).concat(this.afterFns());
var fns = this.beforeAndAfterFns();
var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
this.queueRunnerFactory({
queueableFns: allFns,

View File

@@ -75,7 +75,7 @@ getJasmineRequireObj().Suite = function() {
var allFns = [];
if (this.isExecutable()) {
allFns = this.beforeAllFns;
allFns = allFns.concat(this.beforeAllFns);
for (var i = 0; i < this.children.length; i++) {
allFns.push(wrapChildAsAsync(this.children[i]));