1 /**
  2  * Runner
  3  *
  4  * @constructor
  5  * @param {jasmine.Env} env
  6  */
  7 jasmine.Runner = function(env) {
  8   var self = this;
  9   self.env = env;
 10   self.queue = new jasmine.Queue(env);
 11   self.before_ = [];
 12   self.after_ = [];
 13   self.suites_ = [];
 14 };
 15 
 16 jasmine.Runner.prototype.execute = function() {
 17   var self = this;
 18   if (self.env.reporter.reportRunnerStarting) {
 19     self.env.reporter.reportRunnerStarting(this);
 20   }
 21   self.queue.start(function () {
 22     self.finishCallback();
 23   });
 24 };
 25 
 26 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
 27   beforeEachFunction.typeName = 'beforeEach';
 28   this.before_.splice(0,0,beforeEachFunction);
 29 };
 30 
 31 jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
 32   afterEachFunction.typeName = 'afterEach';
 33   this.after_.splice(0,0,afterEachFunction);
 34 };
 35 
 36 
 37 jasmine.Runner.prototype.finishCallback = function() {
 38   this.env.reporter.reportRunnerResults(this);
 39 };
 40 
 41 jasmine.Runner.prototype.addSuite = function(suite) {
 42   this.suites_.push(suite);
 43 };
 44 
 45 jasmine.Runner.prototype.add = function(block) {
 46   if (block instanceof jasmine.Suite) {
 47     this.addSuite(block);
 48   }
 49   this.queue.add(block);
 50 };
 51 
 52 jasmine.Runner.prototype.specs = function () {
 53   var suites = this.suites();
 54   var specs = [];
 55   for (var i = 0; i < suites.length; i++) {
 56     specs = specs.concat(suites[i].specs());
 57   }
 58   return specs;
 59 };
 60 
 61 jasmine.Runner.prototype.suites = function() {
 62   return this.suites_;
 63 };
 64 
 65 jasmine.Runner.prototype.topLevelSuites = function() {
 66   var topLevelSuites = [];
 67   for (var i = 0; i < this.suites_.length; i++) {
 68     if (!this.suites_[i].parentSuite) {
 69       topLevelSuites.push(this.suites_[i]);
 70     }
 71   }
 72   return topLevelSuites;
 73 };
 74 
 75 jasmine.Runner.prototype.results = function() {
 76   return this.queue.results();
 77 };