runner-wide beforeEach, afterEach support

This commit is contained in:
ragaskar 2009-09-28 16:23:21 -07:00
parent 2588368231
commit a394b564f4
26 changed files with 1659 additions and 1436 deletions

View File

@ -268,6 +268,25 @@ A suite can have a beforeEach declaration. It takes a function that is run befor
};
});
A runner can also have beforeEach declarations. Runner beforeEach functions are executed before every spec in all suites, and execute BEFORE suite beforeEach functions. For example:
var runnerWideFoo = [];
beforeEach(function () {
runnerWideFoo.push('runner');
});
describe('some suite', function () {
beforeEach(function () {
runnerWideFoo.push('suite');
}
it('should equal bar', function () {
expect(runnerWideFoo).toEqual(['runner', 'suite']);
};
});
#### afterEach
Similarly, there is an afterEach declaration. It takes a function that is run after each spec. For example:
@ -284,7 +303,30 @@ Similarly, there is an afterEach declaration. It takes a function that is run a
};
it('should equal 0 after', function () {
expect(suiteWideFoo).toEqual(0);
expect(suiteWideFoo).toEqual(0);
};
});
A runner can also have an afterEach declarations. Runner afterEach functions are executed after every spec in all suites, and execute AFTER suite afterEach functions. For example:
var runnerWideFoo = [];
afterEach(function () {
runnerWideFoo.push('runner');
});
describe('some suite', function () {
afterEach(function () {
runnerWideFoo.push('suite');
}
it('should be empty', function () {
expect(runnerWideFoo).toEqual([]);
};
it('should be populated after', function () {
expect(runnerWideFoo).toEqual(['suite', 'runner']);
};
});

View File

@ -258,7 +258,7 @@ ul.inheritsList
</div>
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -300,7 +300,7 @@ ul.inheritsList
</div>
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blankt">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -908,7 +908,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -339,7 +339,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -507,7 +507,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -316,7 +316,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -316,7 +316,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -700,7 +700,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -316,7 +316,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -418,7 +418,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -396,7 +396,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -845,7 +845,7 @@ expect(foo.bar.callCount).toEqual(0);</pre>
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -436,7 +436,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -678,7 +678,7 @@ Jasmine environment.
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:32 GMT-0700 (PDT)
</div>
</body>
</html>

View File

@ -316,7 +316,7 @@ ul.inheritsList
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
Documentation generated by <a href="http://www.jsdoctoolkit.org/" target="_blank">JsDoc Toolkit</a> 2.1.0 on Mon Sep 28 2009 16:21:33 GMT-0700 (PDT)
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -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);
}

View File

@ -72,7 +72,7 @@ describe('Exceptions:', function() {
});
});
var runner = env.currentRunner;
var runner = env.currentRunner();
suite.execute();
fakeTimer.tick(2500);

View File

@ -49,7 +49,7 @@ describe('jasmine.Reporter', function() {
runnerCallback: runnerCallback
});
var runner = env.currentRunner;
var runner = env.currentRunner();
runner.execute();
expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo);

View File

@ -12,6 +12,70 @@ describe('RunnerTest', function() {
env.clearInterval = fakeTimer.clearInterval;
});
describe('beforeEach', function() {
it('should run before each spec for all suites', function () {
var foo;
env.beforeEach(function () {
foo = 0;
});
env.describe('suite 1', function () {
env.it('test 1-1', function() {
foo++;
this.expect(foo).toEqual(1);
});
env.it('test 1-2', function() {
foo++;
this.expect(foo).toEqual(1);
});
});
env.describe('suite 2', function () {
env.it('test 2-1', function() {
foo++;
this.expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(3);
expect(runnerResults.passedCount).toEqual(3);
});
});
describe('afterEach', function() {
it('should run after each spec for all suites', function () {
var foo = 3;
env.afterEach(function () {
foo = foo - 1;
});
env.describe('suite 1', function () {
env.it('test 1-1', function() {
this.expect(foo).toEqual(3);
});
env.it('test 1-2', function() {
this.expect(foo).toEqual(2);
});
});
env.describe('suite 2', function () {
env.it('test 2-1', function() {
this.expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(3);
expect(runnerResults.passedCount).toEqual(3);
});
});
it('should run child suites and specs and generate results when execute is called', function() {
env.describe('one suite description', function () {
env.it('should be a test', function() {
@ -29,9 +93,9 @@ describe('RunnerTest', function() {
});
});
env.currentRunner.execute();
env.currentRunner().execute();
var runnerResults = env.currentRunner.results();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(2);
expect(runnerResults.passedCount).toEqual(1);
expect(runnerResults.failedCount).toEqual(1);
@ -55,9 +119,9 @@ describe('RunnerTest', function() {
});
});
env.currentRunner.execute();
env.currentRunner().execute();
var runnerResults = env.currentRunner.results();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(1);
expect(runnerResults.passedCount).toEqual(0);
expect(runnerResults.failedCount).toEqual(1);
@ -80,9 +144,9 @@ describe('RunnerTest', function() {
});
});
env.currentRunner.execute();
var results = env.currentRunner.results();
env.currentRunner().execute();
var results = env.currentRunner().results();
expect(results.totalCount).toEqual(2);
expect(results.passedCount).toEqual(1);
expect(results.failedCount).toEqual(1);
@ -113,16 +177,16 @@ describe('RunnerTest', function() {
});
});
env.currentRunner.execute();
env.currentRunner().execute();
expect(fakeReporter.reportRunnerResults).wasNotCalled();
fakeTimer.tick(200);
//This blows up the JSApiReporter.
//expect(fakeReporter.reportRunnerResults).wasCalledWith(env.currentRunner);
expect(fakeReporter.reportRunnerResults).wasCalled();
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner.results());
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner().results());
});
});
it("should report when the tests start running", function() {
@ -139,18 +203,19 @@ describe('RunnerTest', function() {
var reportedRunner = fakeReporter.reportRunnerStarting.mostRecentCall.args[0];
expect(reportedRunner.arbitraryVariable).toEqual('foo');
expect(runner.queue.start).wasCalled();
});
it("should return a flat array of all suites, including nested suites", function() {
var suite1, suite2;
suite1 = env.describe("spec 1", function() {
suite2 = env.describe("nested spec", function() {});
suite2 = env.describe("nested spec", function() {
});
});
document.runner = env.currentRunner;
document.runner = env.currentRunner();
var suites = env.currentRunner.suites();
var suites = env.currentRunner().suites();
var suiteDescriptions = [];
for (var i = 0; i < suites.length; i++) {
suiteDescriptions.push(suites[i].getFullName());

View File

@ -864,6 +864,14 @@ describe("jasmine spec running", function () {
it("testNestedDescribes", function() {
var actions = [];
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('outer beforeEach');
@ -914,27 +922,35 @@ describe("jasmine spec running", function () {
var expected = [
"runner beforeEach",
"outer beforeEach",
"outer it 1",
"outer afterEach",
"runner afterEach",
"runner beforeEach",
"outer beforeEach",
"inner 1 beforeEach",
"inner 1 it",
"inner 1 afterEach",
"outer afterEach",
"runner afterEach",
"runner beforeEach",
"outer beforeEach",
"outer it 2",
"outer afterEach",
"runner afterEach",
"runner beforeEach",
"outer beforeEach",
"inner 2 beforeEach",
"inner 2 it",
"inner 2 afterEach",
"outer afterEach"
"outer afterEach",
"runner afterEach"
];
expect(env.equals_(actions, expected)).toEqual(true);
expect(actions).toEqual(expected);
});
it("builds up nested names", function() {
@ -963,7 +979,8 @@ describe("jasmine spec running", function () {
});
});
env.describe('EmptySuite', function() {});
env.describe('EmptySuite', function() {
});
env.describe('NonEmptySuite2', function() {
env.it('should pass', function() {
@ -973,7 +990,7 @@ describe("jasmine spec running", function () {
env.execute();
var runnerResults = env.currentRunner.results();
var runnerResults = env.currentRunner_.results();
expect(runnerResults.totalCount).toEqual(3);
expect(runnerResults.passedCount).toEqual(3);
expect(runnerResults.failedCount).toEqual(0);

View File

@ -6,7 +6,7 @@
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();
@ -64,7 +64,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) {
@ -74,7 +74,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;
@ -87,11 +87,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) {

View File

@ -8,6 +8,8 @@ jasmine.Runner = function(env) {
var self = this;
self.env = env;
self.queue = new jasmine.Queue(env);
self.before_ = [];
self.after_ = [];
self.suites_ = [];
};
@ -21,6 +23,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);
};

View File

@ -9,10 +9,12 @@
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;
@ -118,10 +120,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);
}
};
@ -146,21 +148,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() {

View File

@ -14,8 +14,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_ = [];
};
@ -37,12 +37,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 */
@ -56,7 +56,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);
}