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.specs_ = []; 20 }; 21 22 jasmine.Suite.prototype.getFullName = function() { 23 var fullName = this.description; 24 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { 25 fullName = parentSuite.description + ' ' + fullName; 26 } 27 return fullName; 28 }; 29 30 jasmine.Suite.prototype.finish = function(onComplete) { 31 this.env.reporter.reportSuiteResults(this); 32 this.finished = true; 33 if (typeof(onComplete) == 'function') { 34 onComplete(); 35 } 36 }; 37 38 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { 39 beforeEachFunction.typeName = 'beforeEach'; 40 this.before_.push(beforeEachFunction); 41 }; 42 43 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { 44 afterEachFunction.typeName = 'afterEach'; 45 this.after_.push(afterEachFunction); 46 }; 47 48 jasmine.Suite.prototype.results = function() { 49 return this.queue.results(); 50 }; 51 52 jasmine.Suite.prototype.add = function(block) { 53 if (block instanceof jasmine.Suite) { 54 this.env.currentRunner().addSuite(block); 55 } else { 56 this.specs_.push(block); 57 } 58 this.queue.add(block); 59 }; 60 61 jasmine.Suite.prototype.specs = function() { 62 return this.specs_; 63 }; 64 65 jasmine.Suite.prototype.execute = function(onComplete) { 66 var self = this; 67 this.queue.start(function () { 68 self.finish(onComplete); 69 }); 70 };