1 /**
  2  * Internal representation of a Jasmine suite.
  3  *
  4  * @constructor
  5  * @param {jasmine.Env} env
  6  * @param {String} description
  7  * @param {Function} specDefinitions
  8  * @param {jasmine.Suite} parentSuite
  9  */
 10 jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
 11   var self = this;
 12   self.id = env.nextSuiteId ? env.nextSuiteId() : null;
 13   self.description = description;
 14   self.queue = new jasmine.Queue(env);
 15   self.parentSuite = parentSuite;
 16   self.env = env;
 17   self.before_ = [];
 18   self.after_ = [];
 19   self.children_ = [];
 20   self.suites_ = [];
 21   self.specs_ = [];
 22 };
 23 
 24 jasmine.Suite.prototype.getFullName = function() {
 25   var fullName = this.description;
 26   for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
 27     fullName = parentSuite.description + ' ' + fullName;
 28   }
 29   return fullName;
 30 };
 31 
 32 jasmine.Suite.prototype.finish = function(onComplete) {
 33   this.env.reporter.reportSuiteResults(this);
 34   this.finished = true;
 35   if (typeof(onComplete) == 'function') {
 36     onComplete();
 37   }
 38 };
 39 
 40 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
 41   beforeEachFunction.typeName = 'beforeEach';
 42   this.before_.unshift(beforeEachFunction);
 43 };
 44 
 45 jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
 46   afterEachFunction.typeName = 'afterEach';
 47   this.after_.unshift(afterEachFunction);
 48 };
 49 
 50 jasmine.Suite.prototype.results = function() {
 51   return this.queue.results();
 52 };
 53 
 54 jasmine.Suite.prototype.add = function(suiteOrSpec) {
 55   this.children_.push(suiteOrSpec);
 56   if (suiteOrSpec instanceof jasmine.Suite) {
 57     this.suites_.push(suiteOrSpec);
 58     this.env.currentRunner().addSuite(suiteOrSpec);
 59   } else {
 60     this.specs_.push(suiteOrSpec);
 61   }
 62   this.queue.add(suiteOrSpec);
 63 };
 64 
 65 jasmine.Suite.prototype.specs = function() {
 66   return this.specs_;
 67 };
 68 
 69 jasmine.Suite.prototype.suites = function() {
 70   return this.suites_;
 71 };
 72 
 73 jasmine.Suite.prototype.children = function() {
 74   return this.children_;
 75 };
 76 
 77 jasmine.Suite.prototype.execute = function(onComplete) {
 78   var self = this;
 79   this.queue.start(function () {
 80     self.finish(onComplete);
 81   });
 82 };