diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 7882ca71..bfac4cb7 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -381,6 +381,8 @@ getJasmineRequireObj().Env = function(j$) { var realClearTimeout = j$.getGlobal().clearTimeout; this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler()); + var runnableLookupTable = {}; + var spies = []; this.currentSpec = null; @@ -518,6 +520,8 @@ getJasmineRequireObj().Env = function(j$) { timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout} }); + runnableLookupTable[spec.id] = spec; + if (!self.specFilter(spec)) { spec.disable(); } @@ -556,10 +560,11 @@ getJasmineRequireObj().Env = function(j$) { completeCallback: function() {}, // TODO - hook this up resultCallback: function() {} // TODO - hook this up }); + runnableLookupTable[this.topSuite.id] = this.topSuite; this.currentSuite = this.topSuite; this.suiteFactory = function(description) { - return new suiteConstructor({ + var suite = new suiteConstructor({ env: self, id: self.nextSuiteId(), description: description, @@ -570,13 +575,25 @@ getJasmineRequireObj().Env = function(j$) { self.reporter.suiteDone(attrs); } }); + + runnableLookupTable[suite.id] = suite; + return suite; }; - this.execute = function() { + this.execute = function(runnablesToRun) { + runnablesToRun = runnablesToRun || [this.topSuite.id]; + + var allFns = []; + for(var i = 0; i < runnablesToRun.length; i++) { + var runnable = runnableLookupTable[runnablesToRun[i]]; + allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable)); + } + this.reporter.jasmineStarted({ totalSpecsDefined: totalSpecsDefined }); - this.topSuite.execute(self.reporter.jasmineDone); + + queueRunnerFactory({fns: allFns, onComplete: this.reporter.jasmineDone}); }; this.spyOn = function(obj, methodName) { diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index 7b910a0e..cab66672 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -300,6 +300,42 @@ describe("Env integration", function() { env.execute(); }); + it("Allows specifying which specs and suites to run", function(done) { + var env = new j$.Env(), + calls = [], + suiteCallback = jasmine.createSpy('suite callback'), + firstSpec, + secondSuite; + + var assertions = function() { + expect(calls).toEqual([ + 'third spec', + 'first spec' + ]); + expect(suiteCallback).toHaveBeenCalled(); + done(); + }; + + env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback}); + + env.describe("first suite", function() { + firstSpec = env.it("first spec", function() { + calls.push('first spec'); + }); + env.it("second spec", function() { + calls.push('second spec'); + }); + }); + + secondSuite = env.describe("second suite", function() { + env.it("third spec", function() { + calls.push('third spec'); + }); + }); + + env.execute([secondSuite.id, firstSpec.id]); + }); + it("Mock clock can be installed and used in tests", function(done) { var globalSetTimeout = jasmine.createSpy('globalSetTimeout'), delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'), diff --git a/src/core/Env.js b/src/core/Env.js index ae1cee92..d846c680 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -11,6 +11,8 @@ getJasmineRequireObj().Env = function(j$) { var realClearTimeout = j$.getGlobal().clearTimeout; this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler()); + var runnableLookupTable = {}; + var spies = []; this.currentSpec = null; @@ -148,6 +150,8 @@ getJasmineRequireObj().Env = function(j$) { timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout} }); + runnableLookupTable[spec.id] = spec; + if (!self.specFilter(spec)) { spec.disable(); } @@ -186,10 +190,11 @@ getJasmineRequireObj().Env = function(j$) { completeCallback: function() {}, // TODO - hook this up resultCallback: function() {} // TODO - hook this up }); + runnableLookupTable[this.topSuite.id] = this.topSuite; this.currentSuite = this.topSuite; this.suiteFactory = function(description) { - return new suiteConstructor({ + var suite = new suiteConstructor({ env: self, id: self.nextSuiteId(), description: description, @@ -200,13 +205,25 @@ getJasmineRequireObj().Env = function(j$) { self.reporter.suiteDone(attrs); } }); + + runnableLookupTable[suite.id] = suite; + return suite; }; - this.execute = function() { + this.execute = function(runnablesToRun) { + runnablesToRun = runnablesToRun || [this.topSuite.id]; + + var allFns = []; + for(var i = 0; i < runnablesToRun.length; i++) { + var runnable = runnableLookupTable[runnablesToRun[i]]; + allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable)); + } + this.reporter.jasmineStarted({ totalSpecsDefined: totalSpecsDefined }); - this.topSuite.execute(self.reporter.jasmineDone); + + queueRunnerFactory({fns: allFns, onComplete: this.reporter.jasmineDone}); }; this.spyOn = function(obj, methodName) {