Add versioning to jasmine

This commit is contained in:
ragaskar 2009-08-20 22:16:14 -07:00
parent 9b9a4b6835
commit 3993969c41
6 changed files with 73 additions and 7 deletions

View File

@ -1,12 +1,25 @@
desc 'Builds lib/jasmine from source' desc 'Builds lib/jasmine from source'
task :build do task :build do
require 'json'
# these files must be loaded first version = JSON.parse(File.new("src/version.json").read);
sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"] sources = ["src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)}.sort sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort
old_jasmine_files = Dir.glob('lib/jasmine*.js')
jasmine = File.new('lib/jasmine.js', 'w') 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| sources.each do |source_filename|
jasmine.puts(File.read(source_filename)) jasmine.puts(File.read(source_filename))
end end

View File

@ -512,6 +512,13 @@ jasmine.include = function(url, opt_global) {
return eval(xhr.responseText); return eval(xhr.responseText);
} }
}; };
jasmine.version_= {
"major": 0,
"minor": 9,
"build": 0,
"revision": 0
};
/** /**
* @namespace * @namespace
*/ */
@ -601,6 +608,17 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.setInterval = jasmine.setInterval;
jasmine.Env.prototype.clearInterval = jasmine.clearInterval; 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. * Register a reporter to receive status updates from Jasmine.
* @param {jasmine.Reporter} reporter An object which will receive status updates. * @param {jasmine.Reporter} reporter An object which will receive status updates.
@ -799,8 +817,7 @@ jasmine.Block = function(env, func, spec) {
this.spec = spec; this.spec = spec;
}; };
jasmine.Block.prototype.execute = function(onComplete) { jasmine.Block.prototype.execute = function(onComplete) {
this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...');
try { try {
this.func.apply(this.spec); this.func.apply(this.spec);
} catch (e) { } catch (e) {
@ -1651,6 +1668,7 @@ jasmine.Spec.prototype.execute = function(onComplete) {
spec.finish(onComplete); spec.finish(onComplete);
return; return;
} }
this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...');
spec.env.currentSpec = spec; spec.env.currentSpec = spec;
spec.env.currentlyRunningTests = true; spec.env.currentlyRunningTests = true;

6
spec/suites/BaseTest.js Normal file
View File

@ -0,0 +1,6 @@
describe("base", function() {
describe("version", function() {
});
});

View File

@ -8,6 +8,18 @@ describe("jasmine.Env", function() {
fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]); 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() { it("should allow reporters to be registered", function() {
env.addReporter(fakeReporter); env.addReporter(fakeReporter);
env.reporter.log("message"); env.reporter.log("message");

View File

@ -28,6 +28,17 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.setInterval = jasmine.setInterval;
jasmine.Env.prototype.clearInterval = jasmine.clearInterval; 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. * Register a reporter to receive status updates from Jasmine.
* @param {jasmine.Reporter} reporter An object which will receive status updates. * @param {jasmine.Reporter} reporter An object which will receive status updates.

6
src/version.json Normal file
View File

@ -0,0 +1,6 @@
{
"major": 0,
"minor": 9,
"build": 0,
"revision": 0
}