From ab0b2b783c204e24234ea6bc1567f36769acf2e0 Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Thu, 24 Oct 2013 13:43:04 -0700 Subject: [PATCH] Move next spec/next suite ids into closure No longer exposing these from the environment --- spec/core/EnvSpec.js | 8 -------- src/core/Env.js | 29 +++++++++++++---------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index f3b70b87..8098b63e 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -5,14 +5,6 @@ describe("Env", function() { env = new j$.Env(); }); - describe('ids', function() { - it('nextSpecId should return consecutive integers, starting at 0', function() { - expect(env.nextSpecId()).toEqual('spec0'); - expect(env.nextSpecId()).toEqual('spec1'); - expect(env.nextSpecId()).toEqual('spec2'); - }); - }); - describe("reporting", function() { var fakeReporter; diff --git a/src/core/Env.js b/src/core/Env.js index 914ebf8a..266197a3 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -26,13 +26,10 @@ getJasmineRequireObj().Env = function(j$) { "specDone" ]); - this.lastUpdate = 0; this.specFilter = function() { return true; }; - this.nextSpecId_ = 0; - this.nextSuiteId_ = 0; this.equalityTesters_ = []; var customEqualityTesters = []; @@ -42,6 +39,16 @@ getJasmineRequireObj().Env = function(j$) { j$.Expectation.addCoreMatchers(j$.matchers); + var nextSpecId = 0; + var getNextSpecId = function() { + return 'spec' + nextSpecId++; + }; + + var nextSuiteId = 0; + var getNextSuiteId = function() { + return 'suite' + nextSuiteId++; + }; + var expectationFactory = function(actual, spec) { return j$.Expectation.Factory({ util: j$.matchersUtil, @@ -133,7 +140,7 @@ getJasmineRequireObj().Env = function(j$) { totalSpecsDefined++; var spec = new j$.Spec({ - id: self.nextSpecId(), + id: getNextSpecId(), beforeFns: beforeFns(suite), afterFns: afterFns(suite), expectationFactory: expectationFactory, @@ -183,7 +190,7 @@ getJasmineRequireObj().Env = function(j$) { this.topSuite = new j$.Suite({ env: this, - id: this.nextSuiteId(), + id: getNextSuiteId(), description: 'Jasmine__TopLevel__Suite', queueRunner: queueRunnerFactory, completeCallback: function() {}, // TODO - hook this up @@ -195,7 +202,7 @@ getJasmineRequireObj().Env = function(j$) { this.suiteFactory = function(description) { var suite = new suiteConstructor({ env: self, - id: self.nextSuiteId(), + id: getNextSuiteId(), description: description, parentSuite: self.currentSuite, queueRunner: queueRunnerFactory, @@ -273,16 +280,6 @@ getJasmineRequireObj().Env = function(j$) { return j$.version; }; - // TODO: move this to closure - Env.prototype.nextSpecId = function() { - return 'spec' + this.nextSpecId_++; - }; - - // TODO: move this to closure - Env.prototype.nextSuiteId = function() { - return 'suite' + this.nextSuiteId_++; - }; - // TODO: move this to closure Env.prototype.addReporter = function(reporter) { this.reporter.addReporter(reporter);