From 3993969c418028d8cdaff034f6985de8b04bba51 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Thu, 20 Aug 2009 22:16:14 -0700 Subject: [PATCH] Add versioning to jasmine --- Rakefile | 23 ++++++++++++++++++----- lib/{jasmine.js => jasmine-0.9.0.js} | 22 ++++++++++++++++++++-- spec/suites/BaseTest.js | 6 ++++++ spec/suites/EnvTest.js | 12 ++++++++++++ src/Env.js | 11 +++++++++++ src/version.json | 6 ++++++ 6 files changed, 73 insertions(+), 7 deletions(-) rename lib/{jasmine.js => jasmine-0.9.0.js} (98%) create mode 100644 spec/suites/BaseTest.js create mode 100644 src/version.json diff --git a/Rakefile b/Rakefile index f3922e4..45276ce 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,25 @@ desc 'Builds lib/jasmine from source' task :build do + require 'json' - # these files must be loaded first - sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"] + version = JSON.parse(File.new("src/version.json").read); + sources = ["src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"] - sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)}.sort - - jasmine = File.new('lib/jasmine.js', 'w') + sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort + old_jasmine_files = Dir.glob('lib/jasmine*.js') + old_jasmine_files.each do |file| + File.delete(file) + end + jasmine = File.new("lib/jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js", 'w') + jasmine.puts(File.read('src/base.js')) + jasmine.puts %{ +jasmine.version_= { + "major": #{version['major']}, + "minor": #{version['minor']}, + "build": #{version['build']}, + "revision": #{version['revision']} + }; +} sources.each do |source_filename| jasmine.puts(File.read(source_filename)) end diff --git a/lib/jasmine.js b/lib/jasmine-0.9.0.js similarity index 98% rename from lib/jasmine.js rename to lib/jasmine-0.9.0.js index 617cefc..3de1afd 100644 --- a/lib/jasmine.js +++ b/lib/jasmine-0.9.0.js @@ -512,6 +512,13 @@ jasmine.include = function(url, opt_global) { return eval(xhr.responseText); } }; + +jasmine.version_= { + "major": 0, + "minor": 9, + "build": 0, + "revision": 0 + }; /** * @namespace */ @@ -601,6 +608,17 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +jasmine.Env.prototype.version = function () { + if (jasmine.version_) { + return parseInt(jasmine.version_.major + "" + + jasmine.version_.minor + "" + + jasmine.version_.build + "" + + jasmine.version_.revision + ""); + } else { + return 0; + } +}; + /** * Register a reporter to receive status updates from Jasmine. * @param {jasmine.Reporter} reporter An object which will receive status updates. @@ -799,8 +817,7 @@ jasmine.Block = function(env, func, spec) { this.spec = spec; }; -jasmine.Block.prototype.execute = function(onComplete) { - this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...'); +jasmine.Block.prototype.execute = function(onComplete) { try { this.func.apply(this.spec); } catch (e) { @@ -1651,6 +1668,7 @@ jasmine.Spec.prototype.execute = function(onComplete) { spec.finish(onComplete); return; } + this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); spec.env.currentSpec = spec; spec.env.currentlyRunningTests = true; diff --git a/spec/suites/BaseTest.js b/spec/suites/BaseTest.js new file mode 100644 index 0000000..6fb8216 --- /dev/null +++ b/spec/suites/BaseTest.js @@ -0,0 +1,6 @@ +describe("base", function() { + describe("version", function() { + + + }); +}); \ No newline at end of file diff --git a/spec/suites/EnvTest.js b/spec/suites/EnvTest.js index 62676ae..e7e11ce 100644 --- a/spec/suites/EnvTest.js +++ b/spec/suites/EnvTest.js @@ -8,6 +8,18 @@ describe("jasmine.Env", function() { fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]); }); + it("version should return the current version as an int", function() { + var oldVersion = jasmine.version_; + jasmine.version_ = { + "major": 1, + "minor": 9, + "build": 7, + "revision": 8 + }; + expect(env.version()).toEqual(1978); + jasmine.version_ = oldVersion; + }); + it("should allow reporters to be registered", function() { env.addReporter(fakeReporter); env.reporter.log("message"); diff --git a/src/Env.js b/src/Env.js index 1548e7a..2938e9b 100644 --- a/src/Env.js +++ b/src/Env.js @@ -28,6 +28,17 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +jasmine.Env.prototype.version = function () { + if (jasmine.version_) { + return parseInt(jasmine.version_.major + "" + + jasmine.version_.minor + "" + + jasmine.version_.build + "" + + jasmine.version_.revision + ""); + } else { + return 0; + } +}; + /** * Register a reporter to receive status updates from Jasmine. * @param {jasmine.Reporter} reporter An object which will receive status updates. diff --git a/src/version.json b/src/version.json new file mode 100644 index 0000000..f5ac434 --- /dev/null +++ b/src/version.json @@ -0,0 +1,6 @@ +{ + "major": 0, + "minor": 9, + "build": 0, + "revision": 0 +} \ No newline at end of file