From 67d9466e5aff6b3bdb08ab889a3572f60fb97b3d Mon Sep 17 00:00:00 2001 From: Brian Takita Date: Mon, 15 Jun 2009 00:51:45 -0700 Subject: [PATCH 1/9] Ignoring rubymine files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..723ef36f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file From 8723421bc334e50dbeb857f8b94b0d598427b0a4 Mon Sep 17 00:00:00 2001 From: Brian Takita Date: Mon, 15 Jun 2009 00:51:51 -0700 Subject: [PATCH 2/9] Fixed example.html --- example/example.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/example.html b/example/example.html index 000eb99f..1776bfb7 100644 --- a/example/example.html +++ b/example/example.html @@ -13,10 +13,10 @@
From 853f47e4aab5fa00296b74a1387239a04b74b34f Mon Sep 17 00:00:00 2001 From: ragaskar Date: Tue, 16 Jun 2009 07:13:45 -0700 Subject: [PATCH 3/9] Added rake :build task to concat files together. Removed jsUnitMockTimeout.js --- Rakefile | 20 + lib/jasmine.js | 1251 ++++++++++++++++++++++++++++++++++++++ spec/bootstrap.html | 2 +- src/jsUnitMockTimeout.js | 81 --- 4 files changed, 1272 insertions(+), 82 deletions(-) create mode 100644 Rakefile create mode 100644 lib/jasmine.js delete mode 100755 src/jsUnitMockTimeout.js diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..364d2dad --- /dev/null +++ b/Rakefile @@ -0,0 +1,20 @@ +desc 'Builds lib/jasmine from source' +task :build do + sources = [ "src/base.js", + "src/util.js", + "src/Env.js", + "src/ActionCollection.js", + "src/Matchers.js", + "src/NestedResults.js", + "src/PrettyPrinter.js", + "src/QueuedFunction.js", + "src/Reporters.js", + "src/Runner.js", + "src/Spec.js", + "src/Suite.js"] + + jasmine = File.new('lib/jasmine.js', 'w') + sources.each do |source_filename| + jasmine.puts(File.read(source_filename)) + end +end \ No newline at end of file diff --git a/lib/jasmine.js b/lib/jasmine.js new file mode 100644 index 00000000..a82930f3 --- /dev/null +++ b/lib/jasmine.js @@ -0,0 +1,1251 @@ +/* + * Jasmine internal classes & objects + */ + +/** @namespace */ +var jasmine = {}; + +jasmine.unimplementedMethod_ = function() { + throw new Error("unimplemented method"); +}; + +jasmine.bindOriginal_ = function(base, name) { + var original = base[name]; + return function() { + return original.apply(base, arguments); + }; +}; + +jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); +jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); +jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); +jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); + +jasmine.MessageResult = function(text) { + this.type = 'MessageResult'; + this.text = text; + this.trace = new Error(); // todo: test better +}; + +jasmine.ExpectationResult = function(passed, message, details) { + this.type = 'ExpectationResult'; + this.passed = passed; + this.message = message; + this.details = details; + this.trace = new Error(message); // todo: test better +}; + +jasmine.getEnv = function() { + return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); +}; + +jasmine.isArray_ = function(value) { + return value && + typeof value === 'object' && + typeof value.length === 'number' && + typeof value.splice === 'function' && + !(value.propertyIsEnumerable('length')); +}; + +jasmine.pp = function(value) { + var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); + stringPrettyPrinter.format(value); + return stringPrettyPrinter.string; +}; + +jasmine.isDomNode = function(obj) { + return obj['nodeType'] > 0; +}; + +jasmine.any = function(clazz) { + return new jasmine.Matchers.Any(clazz); +}; + +jasmine.createSpy = function(name) { + var spyObj = function() { + spyObj.wasCalled = true; + spyObj.callCount++; + var args = jasmine.util.argsToArray(arguments); + spyObj.mostRecentCall = { + object: this, + args: args + }; + spyObj.argsForCall.push(args); + return spyObj.plan.apply(this, arguments); + }; + + spyObj.identity = name || 'unknown'; + spyObj.isSpy = true; + + spyObj.plan = function() { + }; + + spyObj.andCallThrough = function() { + spyObj.plan = spyObj.originalValue; + return spyObj; + }; + spyObj.andReturn = function(value) { + spyObj.plan = function() { + return value; + }; + return spyObj; + }; + spyObj.andThrow = function(exceptionMsg) { + spyObj.plan = function() { + throw exceptionMsg; + }; + return spyObj; + }; + spyObj.andCallFake = function(fakeFunc) { + spyObj.plan = fakeFunc; + return spyObj; + }; + spyObj.reset = function() { + spyObj.wasCalled = false; + spyObj.callCount = 0; + spyObj.argsForCall = []; + spyObj.mostRecentCall = {}; + }; + spyObj.reset(); + + return spyObj; +}; + +jasmine.createSpyObj = function(baseName, methodNames) { + var obj = {}; + for (var i = 0; i < methodNames.length; i++) { + obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); + } + return obj; +}; + +jasmine.log = function(message) { + jasmine.getEnv().currentSpec.getResults().log(message); +}; + +var spyOn = function(obj, methodName) { + return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +}; + +var it = function(desc, func) { + return jasmine.getEnv().it(desc, func); +}; + +var xit = function(desc, func) { + return jasmine.getEnv().xit(desc, func); +}; + +var expect = function(actual) { + return jasmine.getEnv().currentSpec.expect(actual); +}; + +var runs = function(func) { + jasmine.getEnv().currentSpec.runs(func); +}; + +var waits = function(timeout) { + jasmine.getEnv().currentSpec.waits(timeout); +}; + +var waitsFor = function(timeout, latchFunction, message) { + jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +}; + +var beforeEach = function(beforeEachFunction) { + jasmine.getEnv().beforeEach(beforeEachFunction); +}; + +var afterEach = function(afterEachFunction) { + jasmine.getEnv().afterEach(afterEachFunction); +}; + +var describe = function(description, specDefinitions) { + return jasmine.getEnv().describe(description, specDefinitions); +}; + +var xdescribe = function(description, specDefinitions) { + return jasmine.getEnv().xdescribe(description, specDefinitions); +}; + +jasmine.XmlHttpRequest = XMLHttpRequest; + +// Provide the XMLHttpRequest class for IE 5.x-6.x: +if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { + try { + return new ActiveXObject("Msxml2.XMLHTTP.6.0"); + } catch(e) { + } + try { + return new ActiveXObject("Msxml2.XMLHTTP.3.0"); + } catch(e) { + } + try { + return new ActiveXObject("Msxml2.XMLHTTP"); + } catch(e) { + } + try { + return new ActiveXObject("Microsoft.XMLHTTP"); + } catch(e) { + } + throw new Error("This browser does not support XMLHttpRequest."); +}; + +jasmine.include = function(url, opt_global) { + if (opt_global) { + document.write(' - + diff --git a/src/jsUnitMockTimeout.js b/src/jsUnitMockTimeout.js deleted file mode 100755 index 99a4bf18..00000000 --- a/src/jsUnitMockTimeout.js +++ /dev/null @@ -1,81 +0,0 @@ -// Mock setTimeout, clearTimeout -// Contributed by Pivotal Computer Systems, www.pivotalsf.com - -var Clock = { - timeoutsMade: 0, - scheduledFunctions: {}, - nowMillis: 0, - reset: function() { - this.scheduledFunctions = {}; - this.nowMillis = 0; - this.timeoutsMade = 0; - }, - tick: function(millis) { - var oldMillis = this.nowMillis; - var newMillis = oldMillis + millis; - this.runFunctionsWithinRange(oldMillis, newMillis); - this.nowMillis = newMillis; - }, - runFunctionsWithinRange: function(oldMillis, nowMillis) { - var scheduledFunc; - var funcsToRun = []; - for (var timeoutKey in this.scheduledFunctions) { - scheduledFunc = this.scheduledFunctions[timeoutKey]; - if (scheduledFunc != undefined && - scheduledFunc.runAtMillis >= oldMillis && - scheduledFunc.runAtMillis <= nowMillis) { - funcsToRun.push(scheduledFunc); - this.scheduledFunctions[timeoutKey] = undefined; - } - } - - if (funcsToRun.length > 0) { - funcsToRun.sort(function(a, b) { - return a.runAtMillis - b.runAtMillis; - }); - for (var i = 0; i < funcsToRun.length; ++i) { - try { - this.nowMillis = funcsToRun[i].runAtMillis; - funcsToRun[i].funcToCall(); - if (funcsToRun[i].recurring) { - Clock.scheduleFunction(funcsToRun[i].timeoutKey, - funcsToRun[i].funcToCall, - funcsToRun[i].millis, - true); - } - } catch(e) { - } - } - this.runFunctionsWithinRange(oldMillis, nowMillis); - } - }, - scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { - Clock.scheduledFunctions[timeoutKey] = { - runAtMillis: Clock.nowMillis + millis, - funcToCall: funcToCall, - recurring: recurring, - timeoutKey: timeoutKey, - millis: millis - }; - } -}; - -function setTimeout(funcToCall, millis) { - Clock.timeoutsMade = Clock.timeoutsMade + 1; - Clock.scheduleFunction(Clock.timeoutsMade, funcToCall, millis, false); - return Clock.timeoutsMade; -} - -function setInterval(funcToCall, millis) { - Clock.timeoutsMade = Clock.timeoutsMade + 1; - Clock.scheduleFunction(Clock.timeoutsMade, funcToCall, millis, true); - return Clock.timeoutsMade; -} - -function clearTimeout(timeoutKey) { - Clock.scheduledFunctions[timeoutKey] = undefined; -} - -function clearInterval(timeoutKey) { - Clock.scheduledFunctions[timeoutKey] = undefined; -} From ff5e1d337af0ce97f7a8f142c5c0a7178d4a7304 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Tue, 16 Jun 2009 07:19:15 -0700 Subject: [PATCH 4/9] Fixed bootstrap tests --- spec/bootstrap.html | 3 ++- spec/bootstrap.js | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/bootstrap.html b/spec/bootstrap.html index d2d8ce70..85f2dbcb 100755 --- a/spec/bootstrap.html +++ b/spec/bootstrap.html @@ -5,7 +5,7 @@ Jasmine Tests - + @@ -20,6 +20,7 @@ + diff --git a/spec/bootstrap.js b/spec/bootstrap.js index 6fc42627..3625bc09 100755 --- a/spec/bootstrap.js +++ b/spec/bootstrap.js @@ -54,6 +54,7 @@ Reporter.prototype.summary = function () { var reporter = new Reporter(); function runSuite(filename) { + console.log(filename); var suite = jasmine.include(filename); suite.execute(); emitSuiteResults(filename, suite); @@ -167,15 +168,15 @@ var testResultsAliasing = function () { var runTests = function () { document.getElementById('spinner').style.display = ""; - runSuite('PrettyPrintTest.js'); - runSuite('MatchersTest.js'); - runSuite('SpecRunningTest.js'); - runSuite('NestedResultsTest.js'); - runSuite('ReporterTest.js'); - runSuite('RunnerTest.js'); - runSuite('JsonReporterTest.js'); - runSuite('SpyTest.js'); - runSuite('ExceptionsTest.js'); + runSuite('suites/PrettyPrintTest.js'); + runSuite('suites/MatchersTest.js'); + runSuite('suites/SpecRunningTest.js'); + runSuite('suites/NestedResultsTest.js'); + runSuite('suites/ReporterTest.js'); + runSuite('suites/RunnerTest.js'); + runSuite('suites/JsonReporterTest.js'); + runSuite('suites/SpyTest.js'); + runSuite('suites/ExceptionsTest.js'); // testResultsAliasing(); // this appears to do nothing. From 7b3cfab56305dd4c342fe9144c1134f5bf45e133 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Tue, 16 Jun 2009 07:47:25 -0700 Subject: [PATCH 5/9] Fixed example.html --- example/example.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/example.html b/example/example.html index 1776bfb7..000eb99f 100644 --- a/example/example.html +++ b/example/example.html @@ -13,10 +13,10 @@
From 280c7bcf27a3f8b42fe6ac8c33211ea154a714cd Mon Sep 17 00:00:00 2001 From: pivotal Date: Fri, 19 Jun 2009 11:47:33 -0700 Subject: [PATCH 6/9] jb/dwf - updated Jasmine to move mock-timeout into the src dir & build; rake build simplified --- .gitignore | 3 +- Rakefile | 20 ++---- lib/jasmine.js | 158 ++++++++++++++++++++++++++++++++++++++++++++ spec/runner.html | 2 +- src/mock-timeout.js | 158 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 326 insertions(+), 15 deletions(-) create mode 100755 src/mock-timeout.js diff --git a/.gitignore b/.gitignore index 723ef36f..ba72ec6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea/ +.idea/inspectionProfiles/ \ No newline at end of file diff --git a/Rakefile b/Rakefile index 364d2dad..bcadfe1a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,20 +1,14 @@ desc 'Builds lib/jasmine from source' task :build do - sources = [ "src/base.js", - "src/util.js", - "src/Env.js", - "src/ActionCollection.js", - "src/Matchers.js", - "src/NestedResults.js", - "src/PrettyPrinter.js", - "src/QueuedFunction.js", - "src/Reporters.js", - "src/Runner.js", - "src/Spec.js", - "src/Suite.js"] + + # these files must be better + sources = ["src/base.js", "src/util.js", "src/Env.js"] + + sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)} jasmine = File.new('lib/jasmine.js', 'w') sources.each do |source_filename| jasmine.puts(File.read(source_filename)) end -end \ No newline at end of file +end + diff --git a/lib/jasmine.js b/lib/jasmine.js index a82930f3..8db90549 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -721,6 +721,164 @@ jasmine.Matchers.Any.prototype.toString = function() { return ''; }; +// Mock setTimeout, clearTimeout +// Contributed by Pivotal Computer Systems, www.pivotalsf.com + +jasmine.FakeTimer = function() { + this.reset(); + + var self = this; + self.setTimeout = function(funcToCall, millis) { + self.timeoutsMade++; + self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); + return self.timeoutsMade; + }; + + self.setInterval = function(funcToCall, millis) { + self.timeoutsMade++; + self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); + return self.timeoutsMade; + }; + + self.clearTimeout = function(timeoutKey) { + self.scheduledFunctions[timeoutKey] = undefined; + }; + + self.clearInterval = function(timeoutKey) { + self.scheduledFunctions[timeoutKey] = undefined; + }; + +}; + +jasmine.FakeTimer.prototype.reset = function() { + this.timeoutsMade = 0; + this.scheduledFunctions = {}; + this.nowMillis = 0; +}; + +jasmine.FakeTimer.prototype.tick = function(millis) { + var oldMillis = this.nowMillis; + var newMillis = oldMillis + millis; + this.runFunctionsWithinRange(oldMillis, newMillis); + this.nowMillis = newMillis; +}; + +jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { + var scheduledFunc; + var funcsToRun = []; + for (var timeoutKey in this.scheduledFunctions) { + scheduledFunc = this.scheduledFunctions[timeoutKey]; + if (scheduledFunc != undefined && + scheduledFunc.runAtMillis >= oldMillis && + scheduledFunc.runAtMillis <= nowMillis) { + funcsToRun.push(scheduledFunc); + this.scheduledFunctions[timeoutKey] = undefined; + } + } + + if (funcsToRun.length > 0) { + funcsToRun.sort(function(a, b) { + return a.runAtMillis - b.runAtMillis; + }); + for (var i = 0; i < funcsToRun.length; ++i) { + try { + var funcToRun = funcsToRun[i]; + this.nowMillis = funcToRun.runAtMillis; + funcToRun.funcToCall(); + if (funcToRun.recurring) { + this.scheduleFunction(funcToRun.timeoutKey, + funcToRun.funcToCall, + funcToRun.millis, + true); + } + } catch(e) { + } + } + this.runFunctionsWithinRange(oldMillis, nowMillis); + } +}; + +jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { + this.scheduledFunctions[timeoutKey] = { + runAtMillis: this.nowMillis + millis, + funcToCall: funcToCall, + recurring: recurring, + timeoutKey: timeoutKey, + millis: millis + }; +}; + + +jasmine.Clock = { + defaultFakeTimer: new jasmine.FakeTimer(), + + reset: function() { + jasmine.Clock.assertInstalled(); + jasmine.Clock.defaultFakeTimer.reset(); + }, + + tick: function(millis) { + jasmine.Clock.assertInstalled(); + jasmine.Clock.defaultFakeTimer.tick(millis); + }, + + runFunctionsWithinRange: function(oldMillis, nowMillis) { + jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); + }, + + scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { + jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); + }, + + useMock: function() { + var spec = jasmine.getEnv().currentSpec; + spec.after(jasmine.Clock.uninstallMock); + + jasmine.Clock.installMock(); + }, + + installMock: function() { + jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; + }, + + uninstallMock: function() { + jasmine.Clock.assertInstalled(); + jasmine.Clock.installed = jasmine.Clock.real; + }, + + real: { + setTimeout: window.setTimeout, + clearTimeout: window.clearTimeout, + setInterval: window.setInterval, + clearInterval: window.clearInterval + }, + + assertInstalled: function() { + if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { + throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); + } + }, + + installed: null +}; +jasmine.Clock.installed = jasmine.Clock.real; + +window.setTimeout = function(funcToCall, millis) { + return jasmine.Clock.installed.setTimeout.apply(this, arguments); +}; + +window.setInterval = function(funcToCall, millis) { + return jasmine.Clock.installed.setInterval.apply(this, arguments); +}; + +window.clearTimeout = function(timeoutKey) { + return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +}; + +window.clearInterval = function(timeoutKey) { + return jasmine.Clock.installed.clearInterval.apply(this, arguments); +}; + /** * Holds results; allows for the results array to hold another jasmine.NestedResults * diff --git a/spec/runner.html b/spec/runner.html index 0ae2cbf0..fe4bbd87 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -18,11 +18,11 @@ + - - - + Jasmine Test Runner - -

- Running Jasmine Example Specs -

-
+ + + + + + + + + + + diff --git a/example/example.js b/example/example.js index 4c03804e..494539e4 100644 --- a/example/example.js +++ b/example/example.js @@ -1,7 +1,11 @@ -describe('one suite description', function () { - it('should be a test', function() { - runs(function () { +describe('ExampleSuite', function () { + it('should have a passing test', function() { expect(true).toEqual(true); - }); + }); + + describe('Nested Describe', function () { + it('should also have a passing test', function () { + expect(true).toEqual(true); + }); }); }); \ No newline at end of file From 275b83cc52e47e9cba66d8a05320fdd24564dbdf Mon Sep 17 00:00:00 2001 From: ragaskar Date: Wed, 24 Jun 2009 07:44:40 -0700 Subject: [PATCH 8/9] Re-arranged files so that lib represents a standalone drop-in of Jasmine. Killed JSON reporter because it has been succeeded by TrivialReporter.js. Using mock-timeout in src for mock-timeout functionality (instead of maintaining two copies --- .../example.html => lib/example_suite.html | 8 +- example/example.js => lib/example_suite.js | 0 {spec/lib => lib}/json2.js | 0 lib/json_reporter.js | 35 ---- spec/bootstrap.html | 3 +- spec/bootstrap.js | 42 ----- spec/lib/mock-timeout.js | 158 ------------------ spec/suites/JsonReporterTest.js | 53 ------ 8 files changed, 5 insertions(+), 294 deletions(-) rename example/example.html => lib/example_suite.html (73%) rename example/example.js => lib/example_suite.js (100%) rename {spec/lib => lib}/json2.js (100%) delete mode 100644 lib/json_reporter.js delete mode 100755 spec/lib/mock-timeout.js delete mode 100644 spec/suites/JsonReporterTest.js diff --git a/example/example.html b/lib/example_suite.html similarity index 73% rename from example/example.html rename to lib/example_suite.html index 7f28ba65..b59d189a 100644 --- a/example/example.html +++ b/lib/example_suite.html @@ -4,12 +4,12 @@ Jasmine Test Runner - - - + + +