runner-wide beforeEach, afterEach support
This commit is contained in:
@@ -517,7 +517,7 @@ jasmine.version_= {
|
||||
"major": 0,
|
||||
"minor": 9,
|
||||
"build": 0,
|
||||
"revision": 1254161532
|
||||
"revision": 1254180093
|
||||
};
|
||||
/**
|
||||
* @namespace
|
||||
@@ -586,7 +586,7 @@ jasmine.util.argsToArray = function(args) {
|
||||
jasmine.Env = function() {
|
||||
this.currentSpec = null;
|
||||
this.currentSuite = null;
|
||||
this.currentRunner = new jasmine.Runner(this);
|
||||
this.currentRunner_ = new jasmine.Runner(this);
|
||||
this.currentlyRunningTests = false;
|
||||
|
||||
this.reporter = new jasmine.MultiReporter();
|
||||
@@ -644,7 +644,7 @@ jasmine.Env.prototype.addReporter = function(reporter) {
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.execute = function() {
|
||||
this.currentRunner.execute();
|
||||
this.currentRunner_.execute();
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
@@ -654,7 +654,7 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
if (parentSuite) {
|
||||
parentSuite.add(suite);
|
||||
} else {
|
||||
this.currentRunner.add(suite);
|
||||
this.currentRunner_.add(suite);
|
||||
}
|
||||
|
||||
this.currentSuite = suite;
|
||||
@@ -667,11 +667,24 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
|
||||
this.currentSuite.beforeEach(beforeEachFunction);
|
||||
if (this.currentSuite) {
|
||||
this.currentSuite.beforeEach(beforeEachFunction);
|
||||
} else {
|
||||
this.currentRunner_.beforeEach(beforeEachFunction);
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.currentRunner = function () {
|
||||
return this.currentRunner_;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.afterEach = function(afterEachFunction) {
|
||||
this.currentSuite.afterEach(afterEachFunction);
|
||||
if (this.currentSuite) {
|
||||
this.currentSuite.afterEach(afterEachFunction);
|
||||
} else {
|
||||
this.currentRunner_.afterEach(afterEachFunction);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
|
||||
@@ -1548,6 +1561,8 @@ jasmine.Runner = function(env) {
|
||||
var self = this;
|
||||
self.env = env;
|
||||
self.queue = new jasmine.Queue(env);
|
||||
self.before_ = [];
|
||||
self.after_ = [];
|
||||
self.suites_ = [];
|
||||
};
|
||||
|
||||
@@ -1561,6 +1576,17 @@ jasmine.Runner.prototype.execute = function() {
|
||||
});
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
|
||||
beforeEachFunction.typeName = 'beforeEach';
|
||||
this.before_.push(beforeEachFunction);
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
|
||||
afterEachFunction.typeName = 'afterEach';
|
||||
this.after_.push(afterEachFunction);
|
||||
};
|
||||
|
||||
|
||||
jasmine.Runner.prototype.finishCallback = function() {
|
||||
this.env.reporter.reportRunnerResults(this);
|
||||
};
|
||||
@@ -1605,10 +1631,12 @@ jasmine.Runner.prototype.getResults = function() {
|
||||
jasmine.Spec = function(env, suite, description) {
|
||||
if (!env) {
|
||||
throw new Error('jasmine.Env() required');
|
||||
};
|
||||
}
|
||||
;
|
||||
if (!suite) {
|
||||
throw new Error('jasmine.Suite() required');
|
||||
};
|
||||
}
|
||||
;
|
||||
var spec = this;
|
||||
spec.id = env.nextSpecId ? env.nextSpecId() : null;
|
||||
spec.env = env;
|
||||
@@ -1714,10 +1742,10 @@ jasmine.Spec.prototype.finish = function(onComplete) {
|
||||
|
||||
jasmine.Spec.prototype.after = function(doAfter, test) {
|
||||
|
||||
if (this.queue.isRunning()) {
|
||||
if (this.queue.isRunning()) {
|
||||
this.queue.add(new jasmine.Block(this.env, doAfter, this));
|
||||
} else {
|
||||
this.afterCallbacks.unshift(doAfter);
|
||||
this.afterCallbacks.unshift(doAfter);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1742,21 +1770,26 @@ jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
|
||||
var runner = this.env.currentRunner();
|
||||
for (var suite = this.suite; suite; suite = suite.parentSuite) {
|
||||
if (suite.beforeQueue) {
|
||||
for (var i = 0; i < suite.beforeQueue.length; i++)
|
||||
this.queue.addBefore(new jasmine.Block(this.env, suite.beforeQueue[i], this));
|
||||
for (var i = 0; i < suite.before_.length; i++) {
|
||||
this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < runner.before_.length; i++) {
|
||||
this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
|
||||
}
|
||||
for (i = 0; i < this.afterCallbacks.length; i++) {
|
||||
this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
|
||||
}
|
||||
for (suite = this.suite; suite; suite = suite.parentSuite) {
|
||||
if (suite.afterQueue) {
|
||||
for (var j = 0; j < suite.afterQueue.length; j++)
|
||||
this.queue.add(new jasmine.Block(this.env, suite.afterQueue[j], this));
|
||||
for (var i = 0; i < suite.after_.length; i++) {
|
||||
this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < runner.after_.length; i++) {
|
||||
this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.explodes = function() {
|
||||
@@ -1812,8 +1845,8 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
|
||||
self.queue = new jasmine.Queue(env);
|
||||
self.parentSuite = parentSuite;
|
||||
self.env = env;
|
||||
self.beforeQueue = [];
|
||||
self.afterQueue = [];
|
||||
self.before_ = [];
|
||||
self.after_ = [];
|
||||
self.specs_ = [];
|
||||
};
|
||||
|
||||
@@ -1835,12 +1868,12 @@ jasmine.Suite.prototype.finish = function(onComplete) {
|
||||
|
||||
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
|
||||
beforeEachFunction.typeName = 'beforeEach';
|
||||
this.beforeQueue.push(beforeEachFunction);
|
||||
this.before_.push(beforeEachFunction);
|
||||
};
|
||||
|
||||
jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
|
||||
afterEachFunction.typeName = 'afterEach';
|
||||
this.afterQueue.push(afterEachFunction);
|
||||
this.after_.push(afterEachFunction);
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
@@ -1854,7 +1887,7 @@ jasmine.Suite.prototype.results = function() {
|
||||
|
||||
jasmine.Suite.prototype.add = function(block) {
|
||||
if (block instanceof jasmine.Suite) {
|
||||
this.env.currentRunner.addSuite(block);
|
||||
this.env.currentRunner().addSuite(block);
|
||||
} else {
|
||||
this.specs_.push(block);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user