jasmine/src/Suite.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
* Internal representation of a Jasmine suite.
*
* @constructor
* @param {jasmine.Env} env
* @param {String} description
* @param {Function} specDefinitions
* @param {jasmine.Suite} parentSuite
*/
jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
2009-08-01 22:28:39 +00:00
var self = this;
self.id = env.nextSuiteId_++;
self.description = description;
self.queue = new jasmine.Queue(env);
2009-08-01 22:28:39 +00:00
self.parentSuite = parentSuite;
self.env = env;
self.beforeQueue = [];
self.afterQueue = [];
};
2009-08-01 22:28:39 +00:00
jasmine.Suite.prototype.getFullName = function() {
var fullName = this.description;
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + ' ' + fullName;
}
return fullName;
};
jasmine.Suite.prototype.finish = function(onComplete) {
this.env.reporter.reportSuiteResults(this);
2009-08-01 22:28:39 +00:00
this.finished = true;
if (typeof(onComplete) == 'function') {
onComplete();
2009-08-01 22:28:39 +00:00
}
};
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
beforeEachFunction.typeName = 'beforeEach';
this.beforeQueue.push(beforeEachFunction);
};
jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
afterEachFunction.typeName = 'afterEach';
this.afterQueue.push(afterEachFunction);
};
jasmine.Suite.prototype.getResults = function() {
2009-08-01 22:28:39 +00:00
return this.queue.getResults();
};
jasmine.Suite.prototype.add = function(block) {
if (block instanceof jasmine.Suite) {
this.env.currentRunner.addSuite(block);
}
2009-08-01 22:28:39 +00:00
this.queue.add(block);
};
jasmine.Suite.prototype.execute = function(onComplete) {
var self = this;
this.queue.start(function () { self.finish(onComplete); });
2009-08-01 22:28:39 +00:00
};