diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 44f3026..ce98c1e 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -61,13 +61,14 @@ module Jasmine end class RunAdapter - def initialize(spec_files_or_proc, jasmine_files = nil) + def initialize(spec_files_or_proc, jasmine_files = nil, stylesheets = []) @spec_files_or_proc = spec_files_or_proc @jasmine_files = jasmine_files || [ "/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first), "/__JASMINE_ROOT__/lib/TrivialReporter.js", "/__JASMINE_ROOT__/lib/json2.js" ] + @stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"] + stylesheets end def call(env) @@ -77,7 +78,7 @@ module Jasmine jasmine_files = @jasmine_files jasmine_files = jasmine_files.call if jasmine_files.respond_to?(:call) - css_files = ["/__JASMINE_ROOT__/lib/jasmine.css"] + css_files = @stylesheets body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding) [ @@ -113,12 +114,12 @@ module Jasmine end class SimpleServer - def self.start(port, spec_files_or_proc, mappings, jasmine_files = nil) + def self.start(port, spec_files_or_proc, mappings, jasmine_files = nil, stylesheets = []) require 'thin' config = { '/run.html' => Jasmine::Redirect.new('/'), - '/' => Jasmine::RunAdapter.new(spec_files_or_proc, jasmine_files) + '/' => Jasmine::RunAdapter.new(spec_files_or_proc, jasmine_files, stylesheets) } mappings.each do |from, to| config[from] = Rack::File.new(to) diff --git a/contrib/ruby/run.html b/contrib/ruby/run.html index f11b042..ec6e89f 100644 --- a/contrib/ruby/run.html +++ b/contrib/ruby/run.html @@ -15,7 +15,6 @@ var jsApiReporter; (function() { var jasmineEnv = jasmine.getEnv(); - jasmineEnv.updateInterval = 1000; jsApiReporter = new jasmine.JsApiReporter(); var trivialReporter = new jasmine.TrivialReporter(); diff --git a/doc/files.html b/doc/files.html index 43b9de3..e2c07cb 100644 --- a/doc/files.html +++ b/doc/files.html @@ -258,7 +258,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:06 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:34 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 25ff209..b31cb22 100644 --- a/doc/index.html +++ b/doc/index.html @@ -300,7 +300,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:06 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:34 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index a213d4e..95ab2d1 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -908,7 +908,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index c25e4ff..e7536c2 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -339,7 +339,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 7fd634f..5a0113e 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -507,7 +507,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 17e0443..1c3ab1d 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 29aa02c..505481e 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index d3022fe..84abe18 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -700,7 +700,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 1f51f1c..45b5260 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index de9cc93..31dd340 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -418,7 +418,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index a8a6e03..5974b47 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -396,7 +396,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index ac4e9fe..235cd81 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -845,7 +845,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:06 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:34 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index f57de14..43a3c6d 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -436,7 +436,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:06 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:34 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 42a13c0..3064179 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -266,6 +266,29 @@ ul.inheritsList + + + + + + + + + + + + + + + + +
Field Summary
Field AttributesField Name and Description
<static>   +
+ jasmine.UPDATE_INTERVAL +
+
Large or small values here may result in slow test running & "Too much recursion" errors
+
+ @@ -389,6 +412,33 @@ Jasmine environment. +
+ Field Detail +
+ + +
<static> + + + jasmine.UPDATE_INTERVAL + +
+
+ Large or small values here may result in slow test running & "Too much recursion" errors + + +
+ + + + + + + + + + + @@ -678,7 +728,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:05 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:33 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 780b4e8..66bbe36 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Sep 29 2009 22:08:06 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:46:34 GMT-0700 (PDT)
diff --git a/doc/symbols/src/lib_jasmine-0.9.0.js.html b/doc/symbols/src/lib_jasmine-0.9.0.js.html index 4f59dad..a077a2a 100644 --- a/doc/symbols/src/lib_jasmine-0.9.0.js.html +++ b/doc/symbols/src/lib_jasmine-0.9.0.js.html @@ -20,2141 +20,2159 @@ 13 }; 14 15 /** - 16 * Allows for bound functions to be comapred. Internal use only. - 17 * - 18 * @ignore - 19 * @private - 20 * @param base {Object} bound 'this' for the function - 21 * @param name {Function} function to find - 22 */ - 23 jasmine.bindOriginal_ = function(base, name) { - 24 var original = base[name]; - 25 return function() { - 26 return original.apply(base, arguments); - 27 }; - 28 }; - 29 - 30 jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); - 31 jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); - 32 jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); - 33 jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); - 34 - 35 jasmine.MessageResult = function(text) { - 36 this.type = 'MessageResult'; - 37 this.text = text; - 38 this.trace = new Error(); // todo: test better - 39 }; + 16 * Large or small values here may result in slow test running & "Too much recursion" errors + 17 * + 18 */ + 19 jasmine.UPDATE_INTERVAL = 250; + 20 + 21 /** + 22 * Allows for bound functions to be comapred. Internal use only. + 23 * + 24 * @ignore + 25 * @private + 26 * @param base {Object} bound 'this' for the function + 27 * @param name {Function} function to find + 28 */ + 29 jasmine.bindOriginal_ = function(base, name) { + 30 var original = base[name]; + 31 return function() { + 32 return original.apply(base, arguments); + 33 }; + 34 }; + 35 + 36 jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); + 37 jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); + 38 jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); + 39 jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); 40 - 41 jasmine.ExpectationResult = function(passed, message, details) { - 42 this.type = 'ExpectationResult'; - 43 this.passed_ = passed; - 44 this.message = message; - 45 this.details = details; - 46 this.trace = new Error(message); // todo: test better - 47 }; - 48 - 49 jasmine.ExpectationResult.prototype.passed = function () { - 50 return this.passed_; - 51 }; - 52 - 53 /** - 54 * Getter for the Jasmine environment. Ensures one gets created - 55 */ - 56 jasmine.getEnv = function() { - 57 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); - 58 }; - 59 - 60 /** - 61 * @ignore - 62 * @private - 63 * @param value - 64 * @returns {Boolean} - 65 */ - 66 jasmine.isArray_ = function(value) { - 67 return value && - 68 typeof value === 'object' && - 69 typeof value.length === 'number' && - 70 typeof value.splice === 'function' && - 71 !(value.propertyIsEnumerable('length')); - 72 }; - 73 - 74 /** - 75 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. - 76 * - 77 * @param value {Object} an object to be outputted - 78 * @returns {String} - 79 */ - 80 jasmine.pp = function(value) { - 81 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); - 82 stringPrettyPrinter.format(value); - 83 return stringPrettyPrinter.string; - 84 }; - 85 - 86 /** - 87 * Returns true if the object is a DOM Node. - 88 * - 89 * @param {Object} obj object to check - 90 * @returns {Boolean} - 91 */ - 92 jasmine.isDomNode = function(obj) { - 93 return obj['nodeType'] > 0; - 94 }; - 95 - 96 /** - 97 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. - 98 * - 99 * @example -100 * // don't care about which function is passed in, as long as it's a function -101 * expect(mySpy).wasCalledWith(jasmine.any(Function)); -102 * -103 * @param {Class} clazz -104 * @returns matchable object of the type clazz -105 */ -106 jasmine.any = function(clazz) { -107 return new jasmine.Matchers.Any(clazz); -108 }; -109 -110 /** -111 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. -112 * -113 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine -114 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. -115 * -116 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) -117 * Spies are torn down at the end of every spec. + 41 jasmine.MessageResult = function(text) { + 42 this.type = 'MessageResult'; + 43 this.text = text; + 44 this.trace = new Error(); // todo: test better + 45 }; + 46 + 47 jasmine.ExpectationResult = function(passed, message, details) { + 48 this.type = 'ExpectationResult'; + 49 this.passed_ = passed; + 50 this.message = message; + 51 this.details = details; + 52 this.trace = new Error(message); // todo: test better + 53 }; + 54 + 55 jasmine.ExpectationResult.prototype.passed = function () { + 56 return this.passed_; + 57 }; + 58 + 59 /** + 60 * Getter for the Jasmine environment. Ensures one gets created + 61 */ + 62 jasmine.getEnv = function() { + 63 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); + 64 }; + 65 + 66 /** + 67 * @ignore + 68 * @private + 69 * @param value + 70 * @returns {Boolean} + 71 */ + 72 jasmine.isArray_ = function(value) { + 73 return value && + 74 typeof value === 'object' && + 75 typeof value.length === 'number' && + 76 typeof value.splice === 'function' && + 77 !(value.propertyIsEnumerable('length')); + 78 }; + 79 + 80 /** + 81 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. + 82 * + 83 * @param value {Object} an object to be outputted + 84 * @returns {String} + 85 */ + 86 jasmine.pp = function(value) { + 87 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); + 88 stringPrettyPrinter.format(value); + 89 return stringPrettyPrinter.string; + 90 }; + 91 + 92 /** + 93 * Returns true if the object is a DOM Node. + 94 * + 95 * @param {Object} obj object to check + 96 * @returns {Boolean} + 97 */ + 98 jasmine.isDomNode = function(obj) { + 99 return obj['nodeType'] > 0; +100 }; +101 +102 /** +103 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. +104 * +105 * @example +106 * // don't care about which function is passed in, as long as it's a function +107 * expect(mySpy).wasCalledWith(jasmine.any(Function)); +108 * +109 * @param {Class} clazz +110 * @returns matchable object of the type clazz +111 */ +112 jasmine.any = function(clazz) { +113 return new jasmine.Matchers.Any(clazz); +114 }; +115 +116 /** +117 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. 118 * -119 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. -120 * -121 * @example -122 * // a stub -123 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere +119 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine +120 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. +121 * +122 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) +123 * Spies are torn down at the end of every spec. 124 * -125 * // spy example -126 * var foo = { -127 * not: function(bool) { return !bool; } -128 * } -129 * -130 * // actual foo.not will not be called, execution stops -131 * spyOn(foo, 'not'); -132 -133 // foo.not spied upon, execution will continue to implementation -134 * spyOn(foo, 'not').andCallThrough(); +125 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. +126 * +127 * @example +128 * // a stub +129 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere +130 * +131 * // spy example +132 * var foo = { +133 * not: function(bool) { return !bool; } +134 * } 135 * -136 * // fake example -137 * var foo = { -138 * not: function(bool) { return !bool; } -139 * } -140 * -141 * // foo.not(val) will return val -142 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); -143 * -144 * // mock example -145 * foo.not(7 == 7); -146 * expect(foo.not).wasCalled(); -147 * expect(foo.not).wasCalledWith(true); -148 * -149 * @constructor -150 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj -151 * @param {String} name -152 */ -153 jasmine.Spy = function(name) { -154 /** -155 * The name of the spy, if provided. -156 */ -157 this.identity = name || 'unknown'; -158 /** -159 * Is this Object a spy? -160 */ -161 this.isSpy = true; -162 /** -163 * The acutal function this spy stubs. -164 */ -165 this.plan = function() {}; -166 /** -167 * Tracking of the most recent call to the spy. -168 * @example -169 * var mySpy = jasmine.createSpy('foo'); -170 * mySpy(1, 2); -171 * mySpy.mostRecentCall.args = [1, 2]; -172 */ -173 this.mostRecentCall = {}; -174 -175 /** -176 * Holds arguments for each call to the spy, indexed by call count -177 * @example -178 * var mySpy = jasmine.createSpy('foo'); -179 * mySpy(1, 2); -180 * mySpy(7, 8); -181 * mySpy.mostRecentCall.args = [7, 8]; -182 * mySpy.argsForCall[0] = [1, 2]; -183 * mySpy.argsForCall[1] = [7, 8]; -184 */ -185 this.argsForCall = []; -186 }; -187 -188 /** -189 * Tells a spy to call through to the actual implemenatation. -190 * -191 * @example -192 * var foo = { -193 * bar: function() { // do some stuff } -194 * } -195 * -196 * // defining a spy on an existing property: foo.bar -197 * spyOn(foo, 'bar').andCallThrough(); -198 */ -199 jasmine.Spy.prototype.andCallThrough = function() { -200 this.plan = this.originalValue; -201 return this; -202 }; -203 -204 /** -205 * For setting the return value of a spy. -206 * -207 * @example -208 * // defining a spy from scratch: foo() returns 'baz' -209 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); -210 * -211 * // defining a spy on an existing property: foo.bar() returns 'baz' -212 * spyOn(foo, 'bar').andReturn('baz'); +136 * // actual foo.not will not be called, execution stops +137 * spyOn(foo, 'not'); +138 +139 // foo.not spied upon, execution will continue to implementation +140 * spyOn(foo, 'not').andCallThrough(); +141 * +142 * // fake example +143 * var foo = { +144 * not: function(bool) { return !bool; } +145 * } +146 * +147 * // foo.not(val) will return val +148 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); +149 * +150 * // mock example +151 * foo.not(7 == 7); +152 * expect(foo.not).wasCalled(); +153 * expect(foo.not).wasCalledWith(true); +154 * +155 * @constructor +156 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj +157 * @param {String} name +158 */ +159 jasmine.Spy = function(name) { +160 /** +161 * The name of the spy, if provided. +162 */ +163 this.identity = name || 'unknown'; +164 /** +165 * Is this Object a spy? +166 */ +167 this.isSpy = true; +168 /** +169 * The acutal function this spy stubs. +170 */ +171 this.plan = function() {}; +172 /** +173 * Tracking of the most recent call to the spy. +174 * @example +175 * var mySpy = jasmine.createSpy('foo'); +176 * mySpy(1, 2); +177 * mySpy.mostRecentCall.args = [1, 2]; +178 */ +179 this.mostRecentCall = {}; +180 +181 /** +182 * Holds arguments for each call to the spy, indexed by call count +183 * @example +184 * var mySpy = jasmine.createSpy('foo'); +185 * mySpy(1, 2); +186 * mySpy(7, 8); +187 * mySpy.mostRecentCall.args = [7, 8]; +188 * mySpy.argsForCall[0] = [1, 2]; +189 * mySpy.argsForCall[1] = [7, 8]; +190 */ +191 this.argsForCall = []; +192 this.calls = []; +193 }; +194 +195 /** +196 * Tells a spy to call through to the actual implemenatation. +197 * +198 * @example +199 * var foo = { +200 * bar: function() { // do some stuff } +201 * } +202 * +203 * // defining a spy on an existing property: foo.bar +204 * spyOn(foo, 'bar').andCallThrough(); +205 */ +206 jasmine.Spy.prototype.andCallThrough = function() { +207 this.plan = this.originalValue; +208 return this; +209 }; +210 +211 /** +212 * For setting the return value of a spy. 213 * -214 * @param {Object} value -215 */ -216 jasmine.Spy.prototype.andReturn = function(value) { -217 this.plan = function() { -218 return value; -219 }; -220 return this; -221 }; -222 -223 /** -224 * For throwing an exception when a spy is called. -225 * -226 * @example -227 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' -228 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); -229 * -230 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' -231 * spyOn(foo, 'bar').andThrow('baz'); +214 * @example +215 * // defining a spy from scratch: foo() returns 'baz' +216 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); +217 * +218 * // defining a spy on an existing property: foo.bar() returns 'baz' +219 * spyOn(foo, 'bar').andReturn('baz'); +220 * +221 * @param {Object} value +222 */ +223 jasmine.Spy.prototype.andReturn = function(value) { +224 this.plan = function() { +225 return value; +226 }; +227 return this; +228 }; +229 +230 /** +231 * For throwing an exception when a spy is called. 232 * -233 * @param {String} exceptionMsg -234 */ -235 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { -236 this.plan = function() { -237 throw exceptionMsg; -238 }; -239 return this; -240 }; -241 -242 /** -243 * Calls an alternate implementation when a spy is called. -244 * -245 * @example -246 * var baz = function() { -247 * // do some stuff, return something -248 * } -249 * // defining a spy from scratch: foo() calls the function baz -250 * var foo = jasmine.createSpy('spy on foo').andCall(baz); +233 * @example +234 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' +235 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); +236 * +237 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' +238 * spyOn(foo, 'bar').andThrow('baz'); +239 * +240 * @param {String} exceptionMsg +241 */ +242 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { +243 this.plan = function() { +244 throw exceptionMsg; +245 }; +246 return this; +247 }; +248 +249 /** +250 * Calls an alternate implementation when a spy is called. 251 * -252 * // defining a spy on an existing property: foo.bar() calls an anonymnous function -253 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); -254 * -255 * @param {Function} fakeFunc -256 */ -257 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { -258 this.plan = fakeFunc; -259 return this; -260 }; -261 -262 /** -263 * Resets all of a spy's the tracking variables so that it can be used again. -264 * -265 * @example -266 * spyOn(foo, 'bar'); -267 * -268 * foo.bar(); -269 * -270 * expect(foo.bar.callCount).toEqual(1); +252 * @example +253 * var baz = function() { +254 * // do some stuff, return something +255 * } +256 * // defining a spy from scratch: foo() calls the function baz +257 * var foo = jasmine.createSpy('spy on foo').andCall(baz); +258 * +259 * // defining a spy on an existing property: foo.bar() calls an anonymnous function +260 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); +261 * +262 * @param {Function} fakeFunc +263 */ +264 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { +265 this.plan = fakeFunc; +266 return this; +267 }; +268 +269 /** +270 * Resets all of a spy's the tracking variables so that it can be used again. 271 * -272 * foo.bar.reset(); -273 * -274 * expect(foo.bar.callCount).toEqual(0); -275 */ -276 jasmine.Spy.prototype.reset = function() { -277 this.wasCalled = false; -278 this.callCount = 0; -279 this.argsForCall = []; -280 this.mostRecentCall = {}; -281 }; -282 -283 jasmine.createSpy = function(name) { -284 -285 var spyObj = function() { -286 spyObj.wasCalled = true; -287 spyObj.callCount++; -288 var args = jasmine.util.argsToArray(arguments); -289 //spyObj.mostRecentCall = { -290 // object: this, -291 // args: args -292 //}; -293 spyObj.mostRecentCall.object = this; -294 spyObj.mostRecentCall.args = args; -295 spyObj.argsForCall.push(args); -296 return spyObj.plan.apply(this, arguments); -297 }; -298 -299 var spy = new jasmine.Spy(name); -300 -301 for(var prop in spy) { -302 spyObj[prop] = spy[prop]; -303 } -304 -305 spyObj.reset(); -306 -307 return spyObj; -308 }; -309 -310 /** -311 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something -312 * large in one call. -313 * -314 * @param {String} baseName name of spy class -315 * @param {Array} methodNames array of names of methods to make spies -316 */ -317 jasmine.createSpyObj = function(baseName, methodNames) { -318 var obj = {}; -319 for (var i = 0; i < methodNames.length; i++) { -320 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); -321 } -322 return obj; -323 }; -324 -325 jasmine.log = function(message) { -326 jasmine.getEnv().currentSpec.log(message); -327 }; -328 -329 /** -330 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. -331 * -332 * @example -333 * // spy example -334 * var foo = { -335 * not: function(bool) { return !bool; } -336 * } -337 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops -338 * -339 * @see jasmine.createSpy -340 * @param obj -341 * @param methodName -342 * @returns a Jasmine spy that can be chained with all spy methods -343 */ -344 var spyOn = function(obj, methodName) { -345 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -346 }; -347 -348 /** -349 * Creates a Jasmine spec that will be added to the current suite. -350 * -351 * // TODO: pending tests -352 * -353 * @example -354 * it('should be true', function() { -355 * expect(true).toEqual(true); -356 * }); +272 * @example +273 * spyOn(foo, 'bar'); +274 * +275 * foo.bar(); +276 * +277 * expect(foo.bar.callCount).toEqual(1); +278 * +279 * foo.bar.reset(); +280 * +281 * expect(foo.bar.callCount).toEqual(0); +282 */ +283 jasmine.Spy.prototype.reset = function() { +284 this.wasCalled = false; +285 this.callCount = 0; +286 this.argsForCall = []; +287 this.calls = []; +288 this.mostRecentCall = {}; +289 }; +290 +291 jasmine.createSpy = function(name) { +292 +293 var spyObj = function() { +294 spyObj.wasCalled = true; +295 spyObj.callCount++; +296 var args = jasmine.util.argsToArray(arguments); +297 spyObj.mostRecentCall.object = this; +298 spyObj.mostRecentCall.args = args; +299 spyObj.argsForCall.push(args); +300 spyObj.calls.push({object: this, args: args}); +301 return spyObj.plan.apply(this, arguments); +302 }; +303 +304 var spy = new jasmine.Spy(name); +305 +306 for(var prop in spy) { +307 spyObj[prop] = spy[prop]; +308 } +309 +310 spyObj.reset(); +311 +312 return spyObj; +313 }; +314 +315 /** +316 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something +317 * large in one call. +318 * +319 * @param {String} baseName name of spy class +320 * @param {Array} methodNames array of names of methods to make spies +321 */ +322 jasmine.createSpyObj = function(baseName, methodNames) { +323 var obj = {}; +324 for (var i = 0; i < methodNames.length; i++) { +325 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); +326 } +327 return obj; +328 }; +329 +330 jasmine.log = function(message) { +331 jasmine.getEnv().currentSpec.log(message); +332 }; +333 +334 /** +335 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. +336 * +337 * @example +338 * // spy example +339 * var foo = { +340 * not: function(bool) { return !bool; } +341 * } +342 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops +343 * +344 * @see jasmine.createSpy +345 * @param obj +346 * @param methodName +347 * @returns a Jasmine spy that can be chained with all spy methods +348 */ +349 var spyOn = function(obj, methodName) { +350 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +351 }; +352 +353 /** +354 * Creates a Jasmine spec that will be added to the current suite. +355 * +356 * // TODO: pending tests 357 * -358 * @param {String} desc description of this specification -359 * @param {Function} func defines the preconditions and expectations of the spec -360 */ -361 var it = function(desc, func) { -362 return jasmine.getEnv().it(desc, func); -363 }; -364 -365 /** -366 * Creates a <em>disabled</em> Jasmine spec. -367 * -368 * A convenience method that allows existing specs to be disabled temporarily during development. -369 * -370 * @param {String} desc description of this specification -371 * @param {Function} func defines the preconditions and expectations of the spec -372 */ -373 var xit = function(desc, func) { -374 return jasmine.getEnv().xit(desc, func); -375 }; -376 -377 /** -378 * Starts a chain for a Jasmine expectation. -379 * -380 * It is passed an Object that is the actual value and should chain to one of the many -381 * jasmine.Matchers functions. -382 * -383 * @param {Object} actual Actual value to test against and expected value -384 */ -385 var expect = function(actual) { -386 return jasmine.getEnv().currentSpec.expect(actual); -387 }; -388 -389 /** -390 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. -391 * -392 * @param {Function} func Function that defines part of a jasmine spec. -393 */ -394 var runs = function(func) { -395 jasmine.getEnv().currentSpec.runs(func); -396 }; -397 -398 /** -399 * Waits for a timeout before moving to the next runs()-defined block. -400 * @param {Number} timeout -401 */ -402 var waits = function(timeout) { -403 jasmine.getEnv().currentSpec.waits(timeout); -404 }; -405 -406 /** -407 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. -408 * -409 * @param {Number} timeout -410 * @param {Function} latchFunction -411 * @param {String} message -412 */ -413 var waitsFor = function(timeout, latchFunction, message) { -414 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); -415 }; -416 -417 /** -418 * A function that is called before each spec in a suite. -419 * -420 * Used for spec setup, including validating assumptions. -421 * -422 * @param {Function} beforeEachFunction -423 */ -424 var beforeEach = function(beforeEachFunction) { -425 jasmine.getEnv().beforeEach(beforeEachFunction); -426 }; -427 -428 /** -429 * A function that is called after each spec in a suite. -430 * -431 * Used for restoring any state that is hijacked during spec execution. -432 * -433 * @param {Function} afterEachFunction -434 */ -435 var afterEach = function(afterEachFunction) { -436 jasmine.getEnv().afterEach(afterEachFunction); -437 }; -438 -439 /** -440 * Defines a suite of specifications. -441 * -442 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared -443 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization -444 * of setup in some tests. -445 * -446 * @example -447 * // TODO: a simple suite -448 * -449 * // TODO: a simple suite with a nested describe block +358 * @example +359 * it('should be true', function() { +360 * expect(true).toEqual(true); +361 * }); +362 * +363 * @param {String} desc description of this specification +364 * @param {Function} func defines the preconditions and expectations of the spec +365 */ +366 var it = function(desc, func) { +367 return jasmine.getEnv().it(desc, func); +368 }; +369 +370 /** +371 * Creates a <em>disabled</em> Jasmine spec. +372 * +373 * A convenience method that allows existing specs to be disabled temporarily during development. +374 * +375 * @param {String} desc description of this specification +376 * @param {Function} func defines the preconditions and expectations of the spec +377 */ +378 var xit = function(desc, func) { +379 return jasmine.getEnv().xit(desc, func); +380 }; +381 +382 /** +383 * Starts a chain for a Jasmine expectation. +384 * +385 * It is passed an Object that is the actual value and should chain to one of the many +386 * jasmine.Matchers functions. +387 * +388 * @param {Object} actual Actual value to test against and expected value +389 */ +390 var expect = function(actual) { +391 return jasmine.getEnv().currentSpec.expect(actual); +392 }; +393 +394 /** +395 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. +396 * +397 * @param {Function} func Function that defines part of a jasmine spec. +398 */ +399 var runs = function(func) { +400 jasmine.getEnv().currentSpec.runs(func); +401 }; +402 +403 /** +404 * Waits for a timeout before moving to the next runs()-defined block. +405 * @param {Number} timeout +406 */ +407 var waits = function(timeout) { +408 jasmine.getEnv().currentSpec.waits(timeout); +409 }; +410 +411 /** +412 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. +413 * +414 * @param {Number} timeout +415 * @param {Function} latchFunction +416 * @param {String} message +417 */ +418 var waitsFor = function(timeout, latchFunction, message) { +419 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +420 }; +421 +422 /** +423 * A function that is called before each spec in a suite. +424 * +425 * Used for spec setup, including validating assumptions. +426 * +427 * @param {Function} beforeEachFunction +428 */ +429 var beforeEach = function(beforeEachFunction) { +430 jasmine.getEnv().beforeEach(beforeEachFunction); +431 }; +432 +433 /** +434 * A function that is called after each spec in a suite. +435 * +436 * Used for restoring any state that is hijacked during spec execution. +437 * +438 * @param {Function} afterEachFunction +439 */ +440 var afterEach = function(afterEachFunction) { +441 jasmine.getEnv().afterEach(afterEachFunction); +442 }; +443 +444 /** +445 * Defines a suite of specifications. +446 * +447 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared +448 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization +449 * of setup in some tests. 450 * -451 * @param {String} description A string, usually the class under test. -452 * @param {Function} specDefinitions function that defines several specs. -453 */ -454 var describe = function(description, specDefinitions) { -455 return jasmine.getEnv().describe(description, specDefinitions); -456 }; -457 -458 /** -459 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. -460 * -461 * @param {String} description A string, usually the class under test. -462 * @param {Function} specDefinitions function that defines several specs. -463 */ -464 var xdescribe = function(description, specDefinitions) { -465 return jasmine.getEnv().xdescribe(description, specDefinitions); -466 }; -467 -468 -469 jasmine.XmlHttpRequest = XMLHttpRequest; -470 -471 // Provide the XMLHttpRequest class for IE 5.x-6.x: -472 if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { -473 try { -474 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); -475 } catch(e) { -476 } -477 try { -478 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); -479 } catch(e) { -480 } -481 try { -482 return new ActiveXObject("Msxml2.XMLHTTP"); -483 } catch(e) { -484 } -485 try { -486 return new ActiveXObject("Microsoft.XMLHTTP"); -487 } catch(e) { -488 } -489 throw new Error("This browser does not support XMLHttpRequest."); -490 }; -491 -492 /** -493 * Adds suite files to an HTML document so that they are executed, thus adding them to the current -494 * Jasmine environment. -495 * -496 * @param {String} url path to the file to include -497 * @param {Boolean} opt_global -498 */ -499 jasmine.include = function(url, opt_global) { -500 if (opt_global) { -501 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); -502 } else { -503 var xhr; -504 try { -505 xhr = new jasmine.XmlHttpRequest(); -506 xhr.open("GET", url, false); -507 xhr.send(null); -508 } catch(e) { -509 throw new Error("couldn't fetch " + url + ": " + e); -510 } -511 -512 return eval(xhr.responseText); -513 } -514 }; -515 -516 jasmine.version_= { -517 "major": 0, -518 "minor": 9, -519 "build": 0, -520 "revision": 1254286811 -521 }; -522 /** -523 * @namespace -524 */ -525 jasmine.util = {}; -526 +451 * @example +452 * // TODO: a simple suite +453 * +454 * // TODO: a simple suite with a nested describe block +455 * +456 * @param {String} description A string, usually the class under test. +457 * @param {Function} specDefinitions function that defines several specs. +458 */ +459 var describe = function(description, specDefinitions) { +460 return jasmine.getEnv().describe(description, specDefinitions); +461 }; +462 +463 /** +464 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. +465 * +466 * @param {String} description A string, usually the class under test. +467 * @param {Function} specDefinitions function that defines several specs. +468 */ +469 var xdescribe = function(description, specDefinitions) { +470 return jasmine.getEnv().xdescribe(description, specDefinitions); +471 }; +472 +473 +474 jasmine.XmlHttpRequest = XMLHttpRequest; +475 +476 // Provide the XMLHttpRequest class for IE 5.x-6.x: +477 if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { +478 try { +479 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); +480 } catch(e) { +481 } +482 try { +483 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); +484 } catch(e) { +485 } +486 try { +487 return new ActiveXObject("Msxml2.XMLHTTP"); +488 } catch(e) { +489 } +490 try { +491 return new ActiveXObject("Microsoft.XMLHTTP"); +492 } catch(e) { +493 } +494 throw new Error("This browser does not support XMLHttpRequest."); +495 }; +496 +497 /** +498 * Adds suite files to an HTML document so that they are executed, thus adding them to the current +499 * Jasmine environment. +500 * +501 * @param {String} url path to the file to include +502 * @param {Boolean} opt_global +503 */ +504 jasmine.include = function(url, opt_global) { +505 if (opt_global) { +506 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); +507 } else { +508 var xhr; +509 try { +510 xhr = new jasmine.XmlHttpRequest(); +511 xhr.open("GET", url, false); +512 xhr.send(null); +513 } catch(e) { +514 throw new Error("couldn't fetch " + url + ": " + e); +515 } +516 +517 return eval(xhr.responseText); +518 } +519 }; +520 +521 jasmine.version_= { +522 "major": 0, +523 "minor": 9, +524 "build": 0, +525 "revision": 1255469309 +526 }; 527 /** -528 * Declare that a child class inherite it's prototype from the parent class. -529 * -530 * @private -531 * @param {Function} childClass -532 * @param {Function} parentClass -533 */ -534 jasmine.util.inherit = function(childClass, parentClass) { -535 var subclass = function() { -536 }; -537 subclass.prototype = parentClass.prototype; -538 childClass.prototype = new subclass; -539 }; -540 -541 jasmine.util.formatException = function(e) { -542 var lineNumber; -543 if (e.line) { -544 lineNumber = e.line; -545 } -546 else if (e.lineNumber) { -547 lineNumber = e.lineNumber; -548 } -549 -550 var file; -551 -552 if (e.sourceURL) { -553 file = e.sourceURL; -554 } -555 else if (e.fileName) { -556 file = e.fileName; -557 } -558 -559 var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString(); -560 -561 if (file && lineNumber) { -562 message += ' in ' + file + ' (line ' + lineNumber + ')'; -563 } -564 -565 return message; -566 }; -567 -568 jasmine.util.htmlEscape = function(str) { -569 if (!str) return str; -570 return str.replace(/&/g, '&') -571 .replace(/</g, '<') -572 .replace(/>/g, '>'); -573 }; -574 -575 jasmine.util.argsToArray = function(args) { -576 var arrayOfArgs = []; -577 for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); -578 return arrayOfArgs; -579 }; -580 -581 /** -582 * Environment for Jasmine -583 * -584 * @constructor -585 */ -586 jasmine.Env = function() { -587 this.currentSpec = null; -588 this.currentSuite = null; -589 this.currentRunner_ = new jasmine.Runner(this); -590 this.currentlyRunningTests = false; -591 -592 this.reporter = new jasmine.MultiReporter(); -593 -594 this.updateInterval = 0; -595 -596 this.updateInterval = 0; -597 this.lastUpdate = 0; -598 this.specFilter = function() { -599 return true; -600 }; -601 -602 this.nextSpecId_ = 0; -603 this.nextSuiteId_ = 0; -604 this.equalityTesters_ = []; -605 }; -606 -607 -608 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; -609 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; -610 jasmine.Env.prototype.setInterval = jasmine.setInterval; -611 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; -612 -613 /** -614 * @returns an object containing jasmine version build info, if set. -615 */ -616 jasmine.Env.prototype.version = function () { -617 if (jasmine.version_) { -618 return jasmine.version_; -619 } else { -620 throw new Error('Version not set'); -621 } -622 }; -623 -624 /** -625 * @returns a sequential integer starting at 0 -626 */ -627 jasmine.Env.prototype.nextSpecId = function () { -628 return this.nextSpecId_++; -629 }; -630 -631 /** -632 * @returns a sequential integer starting at 0 -633 */ -634 jasmine.Env.prototype.nextSuiteId = function () { -635 return this.nextSuiteId_++; -636 }; -637 -638 /** -639 * Register a reporter to receive status updates from Jasmine. -640 * @param {jasmine.Reporter} reporter An object which will receive status updates. -641 */ -642 jasmine.Env.prototype.addReporter = function(reporter) { -643 this.reporter.addReporter(reporter); -644 }; -645 -646 jasmine.Env.prototype.execute = function() { -647 this.currentRunner_.execute(); -648 }; -649 -650 jasmine.Env.prototype.describe = function(description, specDefinitions) { -651 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); +528 * @namespace +529 */ +530 jasmine.util = {}; +531 +532 /** +533 * Declare that a child class inherite it's prototype from the parent class. +534 * +535 * @private +536 * @param {Function} childClass +537 * @param {Function} parentClass +538 */ +539 jasmine.util.inherit = function(childClass, parentClass) { +540 var subclass = function() { +541 }; +542 subclass.prototype = parentClass.prototype; +543 childClass.prototype = new subclass; +544 }; +545 +546 jasmine.util.formatException = function(e) { +547 var lineNumber; +548 if (e.line) { +549 lineNumber = e.line; +550 } +551 else if (e.lineNumber) { +552 lineNumber = e.lineNumber; +553 } +554 +555 var file; +556 +557 if (e.sourceURL) { +558 file = e.sourceURL; +559 } +560 else if (e.fileName) { +561 file = e.fileName; +562 } +563 +564 var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString(); +565 +566 if (file && lineNumber) { +567 message += ' in ' + file + ' (line ' + lineNumber + ')'; +568 } +569 +570 return message; +571 }; +572 +573 jasmine.util.htmlEscape = function(str) { +574 if (!str) return str; +575 return str.replace(/&/g, '&') +576 .replace(/</g, '<') +577 .replace(/>/g, '>'); +578 }; +579 +580 jasmine.util.argsToArray = function(args) { +581 var arrayOfArgs = []; +582 for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); +583 return arrayOfArgs; +584 }; +585 +586 /** +587 * Environment for Jasmine +588 * +589 * @constructor +590 */ +591 jasmine.Env = function() { +592 this.currentSpec = null; +593 this.currentSuite = null; +594 this.currentRunner_ = new jasmine.Runner(this); +595 this.currentlyRunningTests = false; +596 +597 this.reporter = new jasmine.MultiReporter(); +598 +599 this.updateInterval = jasmine.UPDATE_INTERVAL +600 this.lastUpdate = 0; +601 this.specFilter = function() { +602 return true; +603 }; +604 +605 this.nextSpecId_ = 0; +606 this.nextSuiteId_ = 0; +607 this.equalityTesters_ = []; +608 }; +609 +610 +611 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; +612 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; +613 jasmine.Env.prototype.setInterval = jasmine.setInterval; +614 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +615 +616 /** +617 * @returns an object containing jasmine version build info, if set. +618 */ +619 jasmine.Env.prototype.version = function () { +620 if (jasmine.version_) { +621 return jasmine.version_; +622 } else { +623 throw new Error('Version not set'); +624 } +625 }; +626 +627 /** +628 * @returns a sequential integer starting at 0 +629 */ +630 jasmine.Env.prototype.nextSpecId = function () { +631 return this.nextSpecId_++; +632 }; +633 +634 /** +635 * @returns a sequential integer starting at 0 +636 */ +637 jasmine.Env.prototype.nextSuiteId = function () { +638 return this.nextSuiteId_++; +639 }; +640 +641 /** +642 * Register a reporter to receive status updates from Jasmine. +643 * @param {jasmine.Reporter} reporter An object which will receive status updates. +644 */ +645 jasmine.Env.prototype.addReporter = function(reporter) { +646 this.reporter.addReporter(reporter); +647 }; +648 +649 jasmine.Env.prototype.execute = function() { +650 this.currentRunner_.execute(); +651 }; 652 -653 var parentSuite = this.currentSuite; -654 if (parentSuite) { -655 parentSuite.add(suite); -656 } else { -657 this.currentRunner_.add(suite); -658 } -659 -660 this.currentSuite = suite; -661 -662 specDefinitions.call(suite); -663 -664 this.currentSuite = parentSuite; -665 -666 return suite; -667 }; +653 jasmine.Env.prototype.describe = function(description, specDefinitions) { +654 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); +655 +656 var parentSuite = this.currentSuite; +657 if (parentSuite) { +658 parentSuite.add(suite); +659 } else { +660 this.currentRunner_.add(suite); +661 } +662 +663 this.currentSuite = suite; +664 +665 specDefinitions.call(suite); +666 +667 this.currentSuite = parentSuite; 668 -669 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { -670 if (this.currentSuite) { -671 this.currentSuite.beforeEach(beforeEachFunction); -672 } else { -673 this.currentRunner_.beforeEach(beforeEachFunction); -674 } -675 }; -676 -677 jasmine.Env.prototype.currentRunner = function () { -678 return this.currentRunner_; -679 }; -680 -681 jasmine.Env.prototype.afterEach = function(afterEachFunction) { -682 if (this.currentSuite) { -683 this.currentSuite.afterEach(afterEachFunction); -684 } else { -685 this.currentRunner_.afterEach(afterEachFunction); -686 } -687 -688 }; -689 -690 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { -691 return { -692 execute: function() { -693 } -694 }; -695 }; -696 -697 jasmine.Env.prototype.it = function(description, func) { -698 var spec = new jasmine.Spec(this, this.currentSuite, description); -699 this.currentSuite.add(spec); -700 this.currentSpec = spec; -701 -702 if (func) { -703 spec.runs(func); -704 } -705 -706 return spec; -707 }; +669 return suite; +670 }; +671 +672 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { +673 if (this.currentSuite) { +674 this.currentSuite.beforeEach(beforeEachFunction); +675 } else { +676 this.currentRunner_.beforeEach(beforeEachFunction); +677 } +678 }; +679 +680 jasmine.Env.prototype.currentRunner = function () { +681 return this.currentRunner_; +682 }; +683 +684 jasmine.Env.prototype.afterEach = function(afterEachFunction) { +685 if (this.currentSuite) { +686 this.currentSuite.afterEach(afterEachFunction); +687 } else { +688 this.currentRunner_.afterEach(afterEachFunction); +689 } +690 +691 }; +692 +693 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +694 return { +695 execute: function() { +696 } +697 }; +698 }; +699 +700 jasmine.Env.prototype.it = function(description, func) { +701 var spec = new jasmine.Spec(this, this.currentSuite, description); +702 this.currentSuite.add(spec); +703 this.currentSpec = spec; +704 +705 if (func) { +706 spec.runs(func); +707 } 708 -709 jasmine.Env.prototype.xit = function(desc, func) { -710 return { -711 id: this.nextSpecId(), -712 runs: function() { -713 } -714 }; -715 }; -716 -717 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { -718 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { -719 return true; -720 } -721 -722 a.__Jasmine_been_here_before__ = b; -723 b.__Jasmine_been_here_before__ = a; +709 return spec; +710 }; +711 +712 jasmine.Env.prototype.xit = function(desc, func) { +713 return { +714 id: this.nextSpecId(), +715 runs: function() { +716 } +717 }; +718 }; +719 +720 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { +721 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { +722 return true; +723 } 724 -725 var hasKey = function(obj, keyName) { -726 return obj != null && obj[keyName] !== undefined; -727 }; -728 -729 for (var property in b) { -730 if (!hasKey(a, property) && hasKey(b, property)) { -731 mismatchKeys.push("expected has key '" + property + "', but missing from <b>actual</b>."); -732 } -733 } -734 for (property in a) { -735 if (!hasKey(b, property) && hasKey(a, property)) { -736 mismatchKeys.push("<b>expected</b> missing key '" + property + "', but present in actual."); -737 } -738 } -739 for (property in b) { -740 if (property == '__Jasmine_been_here_before__') continue; -741 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { -742 mismatchValues.push("'" + property + "' was<br /><br />'" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "'<br /><br />in expected, but was<br /><br />'" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "'<br /><br />in actual.<br />"); -743 } -744 } -745 -746 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { -747 mismatchValues.push("arrays were not the same length"); -748 } -749 -750 delete a.__Jasmine_been_here_before__; -751 delete b.__Jasmine_been_here_before__; -752 return (mismatchKeys.length == 0 && mismatchValues.length == 0); -753 }; -754 -755 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { -756 mismatchKeys = mismatchKeys || []; -757 mismatchValues = mismatchValues || []; -758 -759 if (a === b) return true; -760 -761 if (a === undefined || a === null || b === undefined || b === null) { -762 return (a == undefined && b == undefined); -763 } -764 -765 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -766 return a === b; -767 } -768 -769 if (a instanceof Date && b instanceof Date) { -770 return a.getTime() == b.getTime(); -771 } -772 -773 if (a instanceof jasmine.Matchers.Any) { -774 return a.matches(b); -775 } -776 -777 if (b instanceof jasmine.Matchers.Any) { -778 return b.matches(a); -779 } -780 -781 if (typeof a === "object" && typeof b === "object") { -782 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -783 } -784 -785 for (var i = 0; i < this.equalityTesters_.length; i++) { -786 var equalityTester = this.equalityTesters_[i]; -787 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -788 if (result !== undefined) return result; -789 } -790 -791 //Straight check -792 return (a === b); -793 }; -794 -795 jasmine.Env.prototype.contains_ = function(haystack, needle) { -796 if (jasmine.isArray_(haystack)) { -797 for (var i = 0; i < haystack.length; i++) { -798 if (this.equals_(haystack[i], needle)) return true; -799 } -800 return false; -801 } -802 return haystack.indexOf(needle) >= 0; -803 }; -804 -805 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -806 this.equalityTesters_.push(equalityTester); -807 }; -808 /** No-op base class for Jasmine reporters. -809 * -810 * @constructor -811 */ -812 jasmine.Reporter = function() { -813 }; -814 -815 //noinspection JSUnusedLocalSymbols -816 jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { -817 }; -818 -819 //noinspection JSUnusedLocalSymbols -820 jasmine.Reporter.prototype.reportRunnerResults = function(runner) { -821 }; -822 -823 //noinspection JSUnusedLocalSymbols -824 jasmine.Reporter.prototype.reportSuiteResults = function(suite) { -825 }; -826 -827 //noinspection JSUnusedLocalSymbols -828 jasmine.Reporter.prototype.reportSpecResults = function(spec) { -829 }; -830 -831 //noinspection JSUnusedLocalSymbols -832 jasmine.Reporter.prototype.log = function(str) { -833 }; -834 -835 /** -836 * Blocks are functions with executable code that make up a spec. -837 * -838 * @constructor -839 * @param {jasmine.Env} env -840 * @param {Function} func -841 * @param {jasmine.Spec} spec -842 */ -843 jasmine.Block = function(env, func, spec) { -844 this.env = env; -845 this.func = func; -846 this.spec = spec; -847 }; -848 -849 jasmine.Block.prototype.execute = function(onComplete) { -850 try { -851 this.func.apply(this.spec); -852 } catch (e) { -853 this.spec.fail(e); -854 } -855 onComplete(); -856 }; -857 /** JavaScript API reporter. -858 * -859 * @constructor -860 */ -861 jasmine.JsApiReporter = function() { -862 this.started = false; -863 this.finished = false; -864 this.suites_ = []; -865 this.results_ = {}; -866 }; -867 -868 jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { -869 this.started = true; -870 var suites = runner.suites(); -871 for (var i = 0; i < suites.length; i++) { -872 var suite = suites[i]; -873 this.suites_.push(this.summarize_(suite)); -874 } -875 }; -876 -877 jasmine.JsApiReporter.prototype.suites = function() { -878 return this.suites_; -879 }; -880 -881 jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { -882 var isSuite = suiteOrSpec instanceof jasmine.Suite -883 var summary = { -884 id: suiteOrSpec.id, -885 name: suiteOrSpec.description, -886 type: isSuite ? 'suite' : 'spec', -887 children: [] -888 }; -889 if (isSuite) { -890 var specs = suiteOrSpec.specs(); -891 for (var i = 0; i < specs.length; i++) { -892 summary.children.push(this.summarize_(specs[i])); -893 } -894 } -895 return summary; -896 }; -897 -898 jasmine.JsApiReporter.prototype.results = function() { -899 return this.results_; -900 }; -901 -902 jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { -903 return this.results_[specId]; -904 }; -905 -906 //noinspection JSUnusedLocalSymbols -907 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { -908 this.finished = true; -909 }; -910 -911 //noinspection JSUnusedLocalSymbols -912 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { -913 }; -914 -915 //noinspection JSUnusedLocalSymbols -916 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { -917 this.results_[spec.id] = { -918 messages: spec.results().getItems(), -919 result: spec.results().failedCount > 0 ? "failed" : "passed" -920 }; -921 }; -922 -923 //noinspection JSUnusedLocalSymbols -924 jasmine.JsApiReporter.prototype.log = function(str) { -925 }; -926 -927 jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ -928 var results = {}; -929 for (var i = 0; i < specIds.length; i++) { -930 var specId = specIds[i]; -931 results[specId] = this.summarizeResult_(this.results_[specId]); -932 } -933 return results; -934 }; -935 -936 jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ -937 var summaryMessages = []; -938 for (var messageIndex in result.messages) { -939 var resultMessage = result.messages[messageIndex]; -940 summaryMessages.push({ -941 text: resultMessage.text, -942 passed: resultMessage.passed ? resultMessage.passed() : true, -943 type: resultMessage.type, -944 message: resultMessage.message, -945 trace: { -946 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : undefined -947 } -948 }); -949 }; -950 -951 var summaryResult = { -952 result : result.result, -953 messages : summaryMessages -954 }; -955 -956 return summaryResult; -957 }; +725 a.__Jasmine_been_here_before__ = b; +726 b.__Jasmine_been_here_before__ = a; +727 +728 var hasKey = function(obj, keyName) { +729 return obj != null && obj[keyName] !== undefined; +730 }; +731 +732 for (var property in b) { +733 if (!hasKey(a, property) && hasKey(b, property)) { +734 mismatchKeys.push("expected has key '" + property + "', but missing from <b>actual</b>."); +735 } +736 } +737 for (property in a) { +738 if (!hasKey(b, property) && hasKey(a, property)) { +739 mismatchKeys.push("<b>expected</b> missing key '" + property + "', but present in actual."); +740 } +741 } +742 for (property in b) { +743 if (property == '__Jasmine_been_here_before__') continue; +744 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { +745 mismatchValues.push("'" + property + "' was<br /><br />'" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "'<br /><br />in expected, but was<br /><br />'" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "'<br /><br />in actual.<br />"); +746 } +747 } +748 +749 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { +750 mismatchValues.push("arrays were not the same length"); +751 } +752 +753 delete a.__Jasmine_been_here_before__; +754 delete b.__Jasmine_been_here_before__; +755 return (mismatchKeys.length == 0 && mismatchValues.length == 0); +756 }; +757 +758 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +759 mismatchKeys = mismatchKeys || []; +760 mismatchValues = mismatchValues || []; +761 +762 if (a === b) return true; +763 +764 if (a === undefined || a === null || b === undefined || b === null) { +765 return (a == undefined && b == undefined); +766 } +767 +768 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +769 return a === b; +770 } +771 +772 if (a instanceof Date && b instanceof Date) { +773 return a.getTime() == b.getTime(); +774 } +775 +776 if (a instanceof jasmine.Matchers.Any) { +777 return a.matches(b); +778 } +779 +780 if (b instanceof jasmine.Matchers.Any) { +781 return b.matches(a); +782 } +783 +784 if (typeof a === "object" && typeof b === "object") { +785 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +786 } +787 +788 for (var i = 0; i < this.equalityTesters_.length; i++) { +789 var equalityTester = this.equalityTesters_[i]; +790 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); +791 if (result !== undefined) return result; +792 } +793 +794 //Straight check +795 return (a === b); +796 }; +797 +798 jasmine.Env.prototype.contains_ = function(haystack, needle) { +799 if (jasmine.isArray_(haystack)) { +800 for (var i = 0; i < haystack.length; i++) { +801 if (this.equals_(haystack[i], needle)) return true; +802 } +803 return false; +804 } +805 return haystack.indexOf(needle) >= 0; +806 }; +807 +808 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +809 this.equalityTesters_.push(equalityTester); +810 }; +811 /** No-op base class for Jasmine reporters. +812 * +813 * @constructor +814 */ +815 jasmine.Reporter = function() { +816 }; +817 +818 //noinspection JSUnusedLocalSymbols +819 jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { +820 }; +821 +822 //noinspection JSUnusedLocalSymbols +823 jasmine.Reporter.prototype.reportRunnerResults = function(runner) { +824 }; +825 +826 //noinspection JSUnusedLocalSymbols +827 jasmine.Reporter.prototype.reportSuiteResults = function(suite) { +828 }; +829 +830 //noinspection JSUnusedLocalSymbols +831 jasmine.Reporter.prototype.reportSpecResults = function(spec) { +832 }; +833 +834 //noinspection JSUnusedLocalSymbols +835 jasmine.Reporter.prototype.log = function(str) { +836 }; +837 +838 /** +839 * Blocks are functions with executable code that make up a spec. +840 * +841 * @constructor +842 * @param {jasmine.Env} env +843 * @param {Function} func +844 * @param {jasmine.Spec} spec +845 */ +846 jasmine.Block = function(env, func, spec) { +847 this.env = env; +848 this.func = func; +849 this.spec = spec; +850 }; +851 +852 jasmine.Block.prototype.execute = function(onComplete) { +853 try { +854 this.func.apply(this.spec); +855 } catch (e) { +856 this.spec.fail(e); +857 } +858 onComplete(); +859 }; +860 /** JavaScript API reporter. +861 * +862 * @constructor +863 */ +864 jasmine.JsApiReporter = function() { +865 this.started = false; +866 this.finished = false; +867 this.suites_ = []; +868 this.results_ = {}; +869 }; +870 +871 jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { +872 this.started = true; +873 var suites = runner.suites(); +874 for (var i = 0; i < suites.length; i++) { +875 var suite = suites[i]; +876 this.suites_.push(this.summarize_(suite)); +877 } +878 }; +879 +880 jasmine.JsApiReporter.prototype.suites = function() { +881 return this.suites_; +882 }; +883 +884 jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { +885 var isSuite = suiteOrSpec instanceof jasmine.Suite +886 var summary = { +887 id: suiteOrSpec.id, +888 name: suiteOrSpec.description, +889 type: isSuite ? 'suite' : 'spec', +890 children: [] +891 }; +892 if (isSuite) { +893 var specs = suiteOrSpec.specs(); +894 for (var i = 0; i < specs.length; i++) { +895 summary.children.push(this.summarize_(specs[i])); +896 } +897 } +898 return summary; +899 }; +900 +901 jasmine.JsApiReporter.prototype.results = function() { +902 return this.results_; +903 }; +904 +905 jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { +906 return this.results_[specId]; +907 }; +908 +909 //noinspection JSUnusedLocalSymbols +910 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { +911 this.finished = true; +912 }; +913 +914 //noinspection JSUnusedLocalSymbols +915 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { +916 }; +917 +918 //noinspection JSUnusedLocalSymbols +919 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { +920 this.results_[spec.id] = { +921 messages: spec.results().getItems(), +922 result: spec.results().failedCount > 0 ? "failed" : "passed" +923 }; +924 }; +925 +926 //noinspection JSUnusedLocalSymbols +927 jasmine.JsApiReporter.prototype.log = function(str) { +928 }; +929 +930 jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ +931 var results = {}; +932 for (var i = 0; i < specIds.length; i++) { +933 var specId = specIds[i]; +934 results[specId] = this.summarizeResult_(this.results_[specId]); +935 } +936 return results; +937 }; +938 +939 jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ +940 var summaryMessages = []; +941 for (var messageIndex in result.messages) { +942 var resultMessage = result.messages[messageIndex]; +943 summaryMessages.push({ +944 text: resultMessage.text, +945 passed: resultMessage.passed ? resultMessage.passed() : true, +946 type: resultMessage.type, +947 message: resultMessage.message, +948 trace: { +949 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : undefined +950 } +951 }); +952 }; +953 +954 var summaryResult = { +955 result : result.result, +956 messages : summaryMessages +957 }; 958 -959 jasmine.Matchers = function(env, actual, results) { -960 this.env = env; -961 this.actual = actual; -962 this.passing_message = 'Passed.'; -963 this.results_ = results || new jasmine.NestedResults(); -964 }; -965 -966 jasmine.Matchers.pp = function(str) { -967 return jasmine.util.htmlEscape(jasmine.pp(str)); -968 }; -969 -970 /** @deprecated */ -971 jasmine.Matchers.prototype.getResults = function() { -972 return this.results_; -973 }; -974 -975 jasmine.Matchers.prototype.results = function() { -976 return this.results_; -977 }; -978 -979 jasmine.Matchers.prototype.report = function(result, failing_message, details) { -980 this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); -981 return result; -982 }; -983 -984 /** -985 * Matcher that compares the actual to the expected using ===. -986 * -987 * @param expected -988 */ -989 jasmine.Matchers.prototype.toBe = function(expected) { -990 return this.report(this.actual === expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -991 + '<br /><br />to be the same object as<br /><br />' + jasmine.Matchers.pp(this.actual) -992 + '<br />'); -993 }; -994 -995 /** -996 * Matcher that compares the actual to the expected using !== -997 * @param expected -998 */ -999 jasmine.Matchers.prototype.toNotBe = function(expected) { -1000 return this.report(this.actual !== expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -1001 + '<br /><br />to be a different object from actual, but they were the same.'); -1002 }; -1003 -1004 /** -1005 * Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. -1006 * -1007 * @param expected -1008 */ -1009 jasmine.Matchers.prototype.toEqual = function(expected) { -1010 var mismatchKeys = []; -1011 var mismatchValues = []; -1012 -1013 var formatMismatches = function(name, array) { -1014 if (array.length == 0) return ''; -1015 var errorOutput = '<br /><br />Different ' + name + ':<br />'; -1016 for (var i = 0; i < array.length; i++) { -1017 errorOutput += array[i] + '<br />'; -1018 } -1019 return errorOutput; -1020 }; -1021 -1022 return this.report(this.env.equals_(this.actual, expected, mismatchKeys, mismatchValues), -1023 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -1024 + '<br /><br />but got<br /><br />' + jasmine.Matchers.pp(this.actual) -1025 + '<br />' -1026 + formatMismatches('Keys', mismatchKeys) -1027 + formatMismatches('Values', mismatchValues), { -1028 matcherName: 'toEqual', expected: expected, actual: this.actual -1029 }); -1030 }; -1031 /** @deprecated */ -1032 jasmine.Matchers.prototype.should_equal = jasmine.Matchers.prototype.toEqual; -1033 -1034 /** -1035 * Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual -1036 * @param expected -1037 */ -1038 jasmine.Matchers.prototype.toNotEqual = function(expected) { -1039 return this.report(!this.env.equals_(this.actual, expected), -1040 'Expected ' + jasmine.Matchers.pp(expected) + ' to not equal ' + jasmine.Matchers.pp(this.actual) + ', but it does.'); -1041 }; -1042 /** @deprecated */ -1043 jasmine.Matchers.prototype.should_not_equal = jasmine.Matchers.prototype.toNotEqual; -1044 -1045 /** -1046 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -1047 * a pattern or a String. -1048 * -1049 * @param reg_exp -1050 */ -1051 jasmine.Matchers.prototype.toMatch = function(reg_exp) { -1052 return this.report((new RegExp(reg_exp).test(this.actual)), -1053 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to match ' + reg_exp + '.'); -1054 }; -1055 /** @deprecated */ -1056 jasmine.Matchers.prototype.should_match = jasmine.Matchers.prototype.toMatch; -1057 -1058 /** -1059 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -1060 * @param reg_exp -1061 */ -1062 jasmine.Matchers.prototype.toNotMatch = function(reg_exp) { -1063 return this.report((!new RegExp(reg_exp).test(this.actual)), -1064 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to not match ' + reg_exp + '.'); -1065 }; -1066 /** @deprecated */ -1067 jasmine.Matchers.prototype.should_not_match = jasmine.Matchers.prototype.toNotMatch; -1068 -1069 /** -1070 * Matcher that compares the acutal to undefined. -1071 */ -1072 jasmine.Matchers.prototype.toBeDefined = function() { -1073 return this.report((this.actual !== undefined), -1074 'Expected a value to be defined but it was undefined.'); -1075 }; -1076 /** @deprecated */ -1077 jasmine.Matchers.prototype.should_be_defined = jasmine.Matchers.prototype.toBeDefined; -1078 -1079 /** -1080 * Matcher that compares the actual to null. -1081 * -1082 */ -1083 jasmine.Matchers.prototype.toBeNull = function() { -1084 return this.report((this.actual === null), -1085 'Expected a value to be null but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1086 }; -1087 /** @deprecated */ -1088 jasmine.Matchers.prototype.should_be_null = jasmine.Matchers.prototype.toBeNull; -1089 -1090 /** -1091 * Matcher that boolean not-nots the actual. -1092 */ -1093 jasmine.Matchers.prototype.toBeTruthy = function() { -1094 return this.report(!!this.actual, -1095 'Expected a value to be truthy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1096 }; -1097 /** @deprecated */ -1098 jasmine.Matchers.prototype.should_be_truthy = jasmine.Matchers.prototype.toBeTruthy; -1099 -1100 /** -1101 * Matcher that boolean nots the actual. -1102 */ -1103 jasmine.Matchers.prototype.toBeFalsy = function() { -1104 return this.report(!this.actual, -1105 'Expected a value to be falsy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1106 }; -1107 /** @deprecated */ -1108 jasmine.Matchers.prototype.should_be_falsy = jasmine.Matchers.prototype.toBeFalsy; -1109 -1110 /** -1111 * Matcher that checks to see if the acutal, a Jasmine spy, was called. -1112 */ -1113 jasmine.Matchers.prototype.wasCalled = function() { -1114 if (!this.actual || !this.actual.isSpy) { -1115 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -1116 } -1117 if (arguments.length > 0) { -1118 return this.report(false, 'wasCalled matcher does not take arguments'); +959 return summaryResult; +960 }; +961 +962 jasmine.Matchers = function(env, actual, results) { +963 this.env = env; +964 this.actual = actual; +965 this.passing_message = 'Passed.'; +966 this.results_ = results || new jasmine.NestedResults(); +967 }; +968 +969 jasmine.Matchers.pp = function(str) { +970 return jasmine.util.htmlEscape(jasmine.pp(str)); +971 }; +972 +973 /** @deprecated */ +974 jasmine.Matchers.prototype.getResults = function() { +975 return this.results_; +976 }; +977 +978 jasmine.Matchers.prototype.results = function() { +979 return this.results_; +980 }; +981 +982 jasmine.Matchers.prototype.report = function(result, failing_message, details) { +983 this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); +984 return result; +985 }; +986 +987 /** +988 * Matcher that compares the actual to the expected using ===. +989 * +990 * @param expected +991 */ +992 jasmine.Matchers.prototype.toBe = function(expected) { +993 return this.report(this.actual === expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +994 + '<br /><br />to be the same object as<br /><br />' + jasmine.Matchers.pp(this.actual) +995 + '<br />'); +996 }; +997 +998 /** +999 * Matcher that compares the actual to the expected using !== +1000 * @param expected +1001 */ +1002 jasmine.Matchers.prototype.toNotBe = function(expected) { +1003 return this.report(this.actual !== expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +1004 + '<br /><br />to be a different object from actual, but they were the same.'); +1005 }; +1006 +1007 /** +1008 * Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. +1009 * +1010 * @param expected +1011 */ +1012 jasmine.Matchers.prototype.toEqual = function(expected) { +1013 var mismatchKeys = []; +1014 var mismatchValues = []; +1015 +1016 var formatMismatches = function(name, array) { +1017 if (array.length == 0) return ''; +1018 var errorOutput = '<br /><br />Different ' + name + ':<br />'; +1019 for (var i = 0; i < array.length; i++) { +1020 errorOutput += array[i] + '<br />'; +1021 } +1022 return errorOutput; +1023 }; +1024 +1025 return this.report(this.env.equals_(this.actual, expected, mismatchKeys, mismatchValues), +1026 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +1027 + '<br /><br />but got<br /><br />' + jasmine.Matchers.pp(this.actual) +1028 + '<br />' +1029 + formatMismatches('Keys', mismatchKeys) +1030 + formatMismatches('Values', mismatchValues), { +1031 matcherName: 'toEqual', expected: expected, actual: this.actual +1032 }); +1033 }; +1034 /** @deprecated */ +1035 jasmine.Matchers.prototype.should_equal = jasmine.Matchers.prototype.toEqual; +1036 +1037 /** +1038 * Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual +1039 * @param expected +1040 */ +1041 jasmine.Matchers.prototype.toNotEqual = function(expected) { +1042 return this.report(!this.env.equals_(this.actual, expected), +1043 'Expected ' + jasmine.Matchers.pp(expected) + ' to not equal ' + jasmine.Matchers.pp(this.actual) + ', but it does.'); +1044 }; +1045 /** @deprecated */ +1046 jasmine.Matchers.prototype.should_not_equal = jasmine.Matchers.prototype.toNotEqual; +1047 +1048 /** +1049 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +1050 * a pattern or a String. +1051 * +1052 * @param reg_exp +1053 */ +1054 jasmine.Matchers.prototype.toMatch = function(reg_exp) { +1055 return this.report((new RegExp(reg_exp).test(this.actual)), +1056 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to match ' + reg_exp + '.'); +1057 }; +1058 /** @deprecated */ +1059 jasmine.Matchers.prototype.should_match = jasmine.Matchers.prototype.toMatch; +1060 +1061 /** +1062 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +1063 * @param reg_exp +1064 */ +1065 jasmine.Matchers.prototype.toNotMatch = function(reg_exp) { +1066 return this.report((!new RegExp(reg_exp).test(this.actual)), +1067 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to not match ' + reg_exp + '.'); +1068 }; +1069 /** @deprecated */ +1070 jasmine.Matchers.prototype.should_not_match = jasmine.Matchers.prototype.toNotMatch; +1071 +1072 /** +1073 * Matcher that compares the acutal to undefined. +1074 */ +1075 jasmine.Matchers.prototype.toBeDefined = function() { +1076 return this.report((this.actual !== undefined), +1077 'Expected a value to be defined but it was undefined.'); +1078 }; +1079 /** @deprecated */ +1080 jasmine.Matchers.prototype.should_be_defined = jasmine.Matchers.prototype.toBeDefined; +1081 +1082 /** +1083 * Matcher that compares the actual to null. +1084 * +1085 */ +1086 jasmine.Matchers.prototype.toBeNull = function() { +1087 return this.report((this.actual === null), +1088 'Expected a value to be null but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1089 }; +1090 /** @deprecated */ +1091 jasmine.Matchers.prototype.should_be_null = jasmine.Matchers.prototype.toBeNull; +1092 +1093 /** +1094 * Matcher that boolean not-nots the actual. +1095 */ +1096 jasmine.Matchers.prototype.toBeTruthy = function() { +1097 return this.report(!!this.actual, +1098 'Expected a value to be truthy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1099 }; +1100 /** @deprecated */ +1101 jasmine.Matchers.prototype.should_be_truthy = jasmine.Matchers.prototype.toBeTruthy; +1102 +1103 /** +1104 * Matcher that boolean nots the actual. +1105 */ +1106 jasmine.Matchers.prototype.toBeFalsy = function() { +1107 return this.report(!this.actual, +1108 'Expected a value to be falsy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1109 }; +1110 /** @deprecated */ +1111 jasmine.Matchers.prototype.should_be_falsy = jasmine.Matchers.prototype.toBeFalsy; +1112 +1113 /** +1114 * Matcher that checks to see if the acutal, a Jasmine spy, was called. +1115 */ +1116 jasmine.Matchers.prototype.wasCalled = function() { +1117 if (!this.actual || !this.actual.isSpy) { +1118 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); 1119 } -1120 return this.report((this.actual.wasCalled), -1121 'Expected spy "' + this.actual.identity + '" to have been called, but it was not.'); -1122 }; -1123 /** @deprecated */ -1124 jasmine.Matchers.prototype.was_called = jasmine.Matchers.prototype.wasCalled; -1125 -1126 /** -1127 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. -1128 */ -1129 jasmine.Matchers.prototype.wasNotCalled = function() { -1130 if (!this.actual || !this.actual.isSpy) { -1131 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -1132 } -1133 return this.report((!this.actual.wasCalled), -1134 'Expected spy "' + this.actual.identity + '" to not have been called, but it was.'); -1135 }; -1136 /** @deprecated */ -1137 jasmine.Matchers.prototype.was_not_called = jasmine.Matchers.prototype.wasNotCalled; -1138 -1139 /** -1140 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. -1141 * -1142 * @example -1143 * -1144 */ -1145 jasmine.Matchers.prototype.wasCalledWith = function() { -1146 if (!this.actual || !this.actual.isSpy) { -1147 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.', { -1148 matcherName: 'wasCalledWith' -1149 }); -1150 } -1151 -1152 var args = jasmine.util.argsToArray(arguments); -1153 -1154 return this.report(this.env.contains_(this.actual.argsForCall, args), -1155 'Expected ' + jasmine.Matchers.pp(this.actual.argsForCall) + ' to contain ' + jasmine.Matchers.pp(args) + ', but it does not.', { -1156 matcherName: 'wasCalledWith', expected: args, actual: this.actual.argsForCall -1157 }); -1158 }; -1159 -1160 /** -1161 * Matcher that checks that the expected item is an element in the actual Array. -1162 * -1163 * @param {Object} item -1164 */ -1165 jasmine.Matchers.prototype.toContain = function(item) { -1166 return this.report(this.env.contains_(this.actual, item), -1167 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to contain ' + jasmine.Matchers.pp(item) + ', but it does not.', { -1168 matcherName: 'toContain', expected: item, actual: this.actual -1169 }); -1170 }; -1171 -1172 /** -1173 * Matcher that checks that the expected item is NOT an element in the actual Array. -1174 * -1175 * @param {Object} item -1176 */ -1177 jasmine.Matchers.prototype.toNotContain = function(item) { -1178 return this.report(!this.env.contains_(this.actual, item), -1179 'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.'); -1180 }; -1181 -1182 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -1183 return this.report(this.actual < expected, -1184 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); -1185 }; -1186 -1187 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -1188 return this.report(this.actual > expected, -1189 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); -1190 }; -1191 -1192 /** -1193 * Matcher that checks that the expected exception was thrown by the actual. -1194 * -1195 * @param {String} expectedException -1196 */ -1197 jasmine.Matchers.prototype.toThrow = function(expectedException) { -1198 var exception = null; -1199 try { -1200 this.actual(); -1201 } catch (e) { -1202 exception = e; -1203 } -1204 if (expectedException !== undefined) { -1205 if (exception == null) { -1206 return this.report(false, "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it did not."); -1207 } -1208 return this.report( -1209 this.env.equals_( -1210 exception.message || exception, -1211 expectedException.message || expectedException), -1212 "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it threw " + jasmine.Matchers.pp(exception) + "."); -1213 } else { -1214 return this.report(exception != null, "Expected function to throw an exception, but it did not."); -1215 } -1216 }; -1217 -1218 jasmine.Matchers.Any = function(expectedClass) { -1219 this.expectedClass = expectedClass; -1220 }; -1221 -1222 jasmine.Matchers.Any.prototype.matches = function(other) { -1223 if (this.expectedClass == String) { -1224 return typeof other == 'string' || other instanceof String; -1225 } -1226 -1227 if (this.expectedClass == Number) { -1228 return typeof other == 'number' || other instanceof Number; -1229 } -1230 -1231 if (this.expectedClass == Function) { -1232 return typeof other == 'function' || other instanceof Function; -1233 } -1234 -1235 if (this.expectedClass == Object) { -1236 return typeof other == 'object'; -1237 } -1238 -1239 return other instanceof this.expectedClass; -1240 }; +1120 if (arguments.length > 0) { +1121 return this.report(false, 'wasCalled matcher does not take arguments'); +1122 } +1123 return this.report((this.actual.wasCalled), +1124 'Expected spy "' + this.actual.identity + '" to have been called, but it was not.'); +1125 }; +1126 /** @deprecated */ +1127 jasmine.Matchers.prototype.was_called = jasmine.Matchers.prototype.wasCalled; +1128 +1129 /** +1130 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. +1131 */ +1132 jasmine.Matchers.prototype.wasNotCalled = function() { +1133 if (!this.actual || !this.actual.isSpy) { +1134 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +1135 } +1136 return this.report((!this.actual.wasCalled), +1137 'Expected spy "' + this.actual.identity + '" to not have been called, but it was.'); +1138 }; +1139 /** @deprecated */ +1140 jasmine.Matchers.prototype.was_not_called = jasmine.Matchers.prototype.wasNotCalled; +1141 +1142 /** +1143 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +1144 * +1145 * @example +1146 * +1147 */ +1148 jasmine.Matchers.prototype.wasCalledWith = function() { +1149 if (!this.actual || !this.actual.isSpy) { +1150 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.', { +1151 matcherName: 'wasCalledWith' +1152 }); +1153 } +1154 +1155 var args = jasmine.util.argsToArray(arguments); +1156 +1157 return this.report(this.env.contains_(this.actual.argsForCall, args), +1158 'Expected ' + jasmine.Matchers.pp(this.actual.argsForCall) + ' to contain ' + jasmine.Matchers.pp(args) + ', but it does not.', { +1159 matcherName: 'wasCalledWith', expected: args, actual: this.actual.argsForCall +1160 }); +1161 }; +1162 +1163 /** +1164 * Matcher that checks that the expected item is an element in the actual Array. +1165 * +1166 * @param {Object} item +1167 */ +1168 jasmine.Matchers.prototype.toContain = function(item) { +1169 return this.report(this.env.contains_(this.actual, item), +1170 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to contain ' + jasmine.Matchers.pp(item) + ', but it does not.', { +1171 matcherName: 'toContain', expected: item, actual: this.actual +1172 }); +1173 }; +1174 +1175 /** +1176 * Matcher that checks that the expected item is NOT an element in the actual Array. +1177 * +1178 * @param {Object} item +1179 */ +1180 jasmine.Matchers.prototype.toNotContain = function(item) { +1181 return this.report(!this.env.contains_(this.actual, item), +1182 'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.'); +1183 }; +1184 +1185 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +1186 return this.report(this.actual < expected, +1187 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); +1188 }; +1189 +1190 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +1191 return this.report(this.actual > expected, +1192 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); +1193 }; +1194 +1195 /** +1196 * Matcher that checks that the expected exception was thrown by the actual. +1197 * +1198 * @param {String} expectedException +1199 */ +1200 jasmine.Matchers.prototype.toThrow = function(expectedException) { +1201 var exception = null; +1202 try { +1203 this.actual(); +1204 } catch (e) { +1205 exception = e; +1206 } +1207 if (expectedException !== undefined) { +1208 if (exception == null) { +1209 return this.report(false, "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it did not."); +1210 } +1211 return this.report( +1212 this.env.equals_( +1213 exception.message || exception, +1214 expectedException.message || expectedException), +1215 "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it threw " + jasmine.Matchers.pp(exception) + "."); +1216 } else { +1217 return this.report(exception != null, "Expected function to throw an exception, but it did not."); +1218 } +1219 }; +1220 +1221 jasmine.Matchers.Any = function(expectedClass) { +1222 this.expectedClass = expectedClass; +1223 }; +1224 +1225 jasmine.Matchers.Any.prototype.matches = function(other) { +1226 if (this.expectedClass == String) { +1227 return typeof other == 'string' || other instanceof String; +1228 } +1229 +1230 if (this.expectedClass == Number) { +1231 return typeof other == 'number' || other instanceof Number; +1232 } +1233 +1234 if (this.expectedClass == Function) { +1235 return typeof other == 'function' || other instanceof Function; +1236 } +1237 +1238 if (this.expectedClass == Object) { +1239 return typeof other == 'object'; +1240 } 1241 -1242 jasmine.Matchers.Any.prototype.toString = function() { -1243 return '<jasmine.any(' + this.expectedClass + ')>'; -1244 }; -1245 -1246 /** -1247 * @constructor -1248 */ -1249 jasmine.MultiReporter = function() { -1250 this.subReporters_ = []; -1251 }; -1252 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); -1253 -1254 jasmine.MultiReporter.prototype.addReporter = function(reporter) { -1255 this.subReporters_.push(reporter); -1256 }; -1257 -1258 (function() { -1259 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; -1260 for (var i = 0; i < functionNames.length; i++) { -1261 var functionName = functionNames[i]; -1262 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { -1263 return function() { -1264 for (var j = 0; j < this.subReporters_.length; j++) { -1265 var subReporter = this.subReporters_[j]; -1266 if (subReporter[functionName]) { -1267 subReporter[functionName].apply(subReporter, arguments); -1268 } -1269 } -1270 }; -1271 })(functionName); -1272 } -1273 })(); -1274 /** -1275 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults -1276 * -1277 * @constructor -1278 */ -1279 jasmine.NestedResults = function() { -1280 /** -1281 * The total count of results -1282 */ -1283 this.totalCount = 0; -1284 /** -1285 * Number of passed results -1286 */ -1287 this.passedCount = 0; -1288 /** -1289 * Number of failed results -1290 */ -1291 this.failedCount = 0; -1292 /** -1293 * Was this suite/spec skipped? -1294 */ -1295 this.skipped = false; -1296 /** -1297 * @ignore -1298 */ -1299 this.items_ = []; -1300 }; -1301 -1302 /** -1303 * Roll up the result counts. -1304 * -1305 * @param result -1306 */ -1307 jasmine.NestedResults.prototype.rollupCounts = function(result) { -1308 this.totalCount += result.totalCount; -1309 this.passedCount += result.passedCount; -1310 this.failedCount += result.failedCount; -1311 }; -1312 -1313 /** -1314 * Tracks a result's message. -1315 * @param message -1316 */ -1317 jasmine.NestedResults.prototype.log = function(message) { -1318 this.items_.push(new jasmine.MessageResult(message)); -1319 }; -1320 -1321 /** -1322 * Getter for the results: message & results. -1323 */ -1324 jasmine.NestedResults.prototype.getItems = function() { -1325 return this.items_; -1326 }; -1327 -1328 /** -1329 * Adds a result, tracking counts (total, passed, & failed) -1330 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result -1331 */ -1332 jasmine.NestedResults.prototype.addResult = function(result) { -1333 if (result.type != 'MessageResult') { -1334 if (result.items_) { -1335 this.rollupCounts(result); -1336 } else { -1337 this.totalCount++; -1338 if (result.passed()) { -1339 this.passedCount++; -1340 } else { -1341 this.failedCount++; -1342 } -1343 } -1344 } -1345 this.items_.push(result); -1346 }; -1347 -1348 /** -1349 * @returns {Boolean} True if <b>everything</b> below passed -1350 */ -1351 jasmine.NestedResults.prototype.passed = function() { -1352 return this.passedCount === this.totalCount; -1353 }; -1354 /** -1355 * Base class for pretty printing for expectation results. -1356 */ -1357 jasmine.PrettyPrinter = function() { -1358 this.ppNestLevel_ = 0; -1359 }; -1360 -1361 /** -1362 * Formats a value in a nice, human-readable string. -1363 * -1364 * @param value -1365 * @returns {String} -1366 */ -1367 jasmine.PrettyPrinter.prototype.format = function(value) { -1368 if (this.ppNestLevel_ > 40) { -1369 // return '(jasmine.pp nested too deeply!)'; -1370 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); -1371 } -1372 -1373 this.ppNestLevel_++; -1374 try { -1375 if (value === undefined) { -1376 this.emitScalar('undefined'); -1377 } else if (value === null) { -1378 this.emitScalar('null'); -1379 } else if (value.navigator && value.frames && value.setTimeout) { -1380 this.emitScalar('<window>'); -1381 } else if (value instanceof jasmine.Matchers.Any) { -1382 this.emitScalar(value.toString()); -1383 } else if (typeof value === 'string') { -1384 this.emitString(value); -1385 } else if (typeof value === 'function') { -1386 this.emitScalar('Function'); -1387 } else if (typeof value.nodeType === 'number') { -1388 this.emitScalar('HTMLNode'); -1389 } else if (value instanceof Date) { -1390 this.emitScalar('Date(' + value + ')'); -1391 } else if (value.__Jasmine_been_here_before__) { -1392 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); -1393 } else if (jasmine.isArray_(value) || typeof value == 'object') { -1394 value.__Jasmine_been_here_before__ = true; -1395 if (jasmine.isArray_(value)) { -1396 this.emitArray(value); -1397 } else { -1398 this.emitObject(value); -1399 } -1400 delete value.__Jasmine_been_here_before__; -1401 } else { -1402 this.emitScalar(value.toString()); -1403 } -1404 } finally { -1405 this.ppNestLevel_--; -1406 } -1407 }; -1408 -1409 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { -1410 for (var property in obj) { -1411 if (property == '__Jasmine_been_here_before__') continue; -1412 fn(property, obj.__lookupGetter__(property) != null); -1413 } -1414 }; -1415 -1416 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -1417 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -1418 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -1419 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; -1420 -1421 jasmine.StringPrettyPrinter = function() { -1422 jasmine.PrettyPrinter.call(this); +1242 return other instanceof this.expectedClass; +1243 }; +1244 +1245 jasmine.Matchers.Any.prototype.toString = function() { +1246 return '<jasmine.any(' + this.expectedClass + ')>'; +1247 }; +1248 +1249 /** +1250 * @constructor +1251 */ +1252 jasmine.MultiReporter = function() { +1253 this.subReporters_ = []; +1254 }; +1255 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); +1256 +1257 jasmine.MultiReporter.prototype.addReporter = function(reporter) { +1258 this.subReporters_.push(reporter); +1259 }; +1260 +1261 (function() { +1262 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; +1263 for (var i = 0; i < functionNames.length; i++) { +1264 var functionName = functionNames[i]; +1265 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { +1266 return function() { +1267 for (var j = 0; j < this.subReporters_.length; j++) { +1268 var subReporter = this.subReporters_[j]; +1269 if (subReporter[functionName]) { +1270 subReporter[functionName].apply(subReporter, arguments); +1271 } +1272 } +1273 }; +1274 })(functionName); +1275 } +1276 })(); +1277 /** +1278 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults +1279 * +1280 * @constructor +1281 */ +1282 jasmine.NestedResults = function() { +1283 /** +1284 * The total count of results +1285 */ +1286 this.totalCount = 0; +1287 /** +1288 * Number of passed results +1289 */ +1290 this.passedCount = 0; +1291 /** +1292 * Number of failed results +1293 */ +1294 this.failedCount = 0; +1295 /** +1296 * Was this suite/spec skipped? +1297 */ +1298 this.skipped = false; +1299 /** +1300 * @ignore +1301 */ +1302 this.items_ = []; +1303 }; +1304 +1305 /** +1306 * Roll up the result counts. +1307 * +1308 * @param result +1309 */ +1310 jasmine.NestedResults.prototype.rollupCounts = function(result) { +1311 this.totalCount += result.totalCount; +1312 this.passedCount += result.passedCount; +1313 this.failedCount += result.failedCount; +1314 }; +1315 +1316 /** +1317 * Tracks a result's message. +1318 * @param message +1319 */ +1320 jasmine.NestedResults.prototype.log = function(message) { +1321 this.items_.push(new jasmine.MessageResult(message)); +1322 }; +1323 +1324 /** +1325 * Getter for the results: message & results. +1326 */ +1327 jasmine.NestedResults.prototype.getItems = function() { +1328 return this.items_; +1329 }; +1330 +1331 /** +1332 * Adds a result, tracking counts (total, passed, & failed) +1333 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result +1334 */ +1335 jasmine.NestedResults.prototype.addResult = function(result) { +1336 if (result.type != 'MessageResult') { +1337 if (result.items_) { +1338 this.rollupCounts(result); +1339 } else { +1340 this.totalCount++; +1341 if (result.passed()) { +1342 this.passedCount++; +1343 } else { +1344 this.failedCount++; +1345 } +1346 } +1347 } +1348 this.items_.push(result); +1349 }; +1350 +1351 /** +1352 * @returns {Boolean} True if <b>everything</b> below passed +1353 */ +1354 jasmine.NestedResults.prototype.passed = function() { +1355 return this.passedCount === this.totalCount; +1356 }; +1357 /** +1358 * Base class for pretty printing for expectation results. +1359 */ +1360 jasmine.PrettyPrinter = function() { +1361 this.ppNestLevel_ = 0; +1362 }; +1363 +1364 /** +1365 * Formats a value in a nice, human-readable string. +1366 * +1367 * @param value +1368 * @returns {String} +1369 */ +1370 jasmine.PrettyPrinter.prototype.format = function(value) { +1371 if (this.ppNestLevel_ > 40) { +1372 // return '(jasmine.pp nested too deeply!)'; +1373 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); +1374 } +1375 +1376 this.ppNestLevel_++; +1377 try { +1378 if (value === undefined) { +1379 this.emitScalar('undefined'); +1380 } else if (value === null) { +1381 this.emitScalar('null'); +1382 } else if (value.navigator && value.frames && value.setTimeout) { +1383 this.emitScalar('<window>'); +1384 } else if (value instanceof jasmine.Matchers.Any) { +1385 this.emitScalar(value.toString()); +1386 } else if (typeof value === 'string') { +1387 this.emitString(value); +1388 } else if (typeof value === 'function') { +1389 this.emitScalar('Function'); +1390 } else if (typeof value.nodeType === 'number') { +1391 this.emitScalar('HTMLNode'); +1392 } else if (value instanceof Date) { +1393 this.emitScalar('Date(' + value + ')'); +1394 } else if (value.__Jasmine_been_here_before__) { +1395 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); +1396 } else if (jasmine.isArray_(value) || typeof value == 'object') { +1397 value.__Jasmine_been_here_before__ = true; +1398 if (jasmine.isArray_(value)) { +1399 this.emitArray(value); +1400 } else { +1401 this.emitObject(value); +1402 } +1403 delete value.__Jasmine_been_here_before__; +1404 } else { +1405 this.emitScalar(value.toString()); +1406 } +1407 } finally { +1408 this.ppNestLevel_--; +1409 } +1410 }; +1411 +1412 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { +1413 for (var property in obj) { +1414 if (property == '__Jasmine_been_here_before__') continue; +1415 fn(property, obj.__lookupGetter__(property) != null); +1416 } +1417 }; +1418 +1419 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; +1420 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; +1421 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; +1422 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; 1423 -1424 this.string = ''; -1425 }; -1426 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); -1427 -1428 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { -1429 this.append(value); -1430 }; -1431 -1432 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { -1433 this.append("'" + value + "'"); -1434 }; -1435 -1436 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { -1437 this.append('[ '); -1438 for (var i = 0; i < array.length; i++) { -1439 if (i > 0) { -1440 this.append(', '); -1441 } -1442 this.format(array[i]); -1443 } -1444 this.append(' ]'); -1445 }; -1446 -1447 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { -1448 var self = this; -1449 this.append('{ '); -1450 var first = true; -1451 -1452 this.iterateObject(obj, function(property, isGetter) { -1453 if (first) { -1454 first = false; -1455 } else { -1456 self.append(', '); -1457 } -1458 -1459 self.append(property); -1460 self.append(' : '); -1461 if (isGetter) { -1462 self.append('<getter>'); -1463 } else { -1464 self.format(obj[property]); -1465 } -1466 }); -1467 -1468 this.append(' }'); -1469 }; +1424 jasmine.StringPrettyPrinter = function() { +1425 jasmine.PrettyPrinter.call(this); +1426 +1427 this.string = ''; +1428 }; +1429 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); +1430 +1431 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { +1432 this.append(value); +1433 }; +1434 +1435 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { +1436 this.append("'" + value + "'"); +1437 }; +1438 +1439 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { +1440 this.append('[ '); +1441 for (var i = 0; i < array.length; i++) { +1442 if (i > 0) { +1443 this.append(', '); +1444 } +1445 this.format(array[i]); +1446 } +1447 this.append(' ]'); +1448 }; +1449 +1450 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { +1451 var self = this; +1452 this.append('{ '); +1453 var first = true; +1454 +1455 this.iterateObject(obj, function(property, isGetter) { +1456 if (first) { +1457 first = false; +1458 } else { +1459 self.append(', '); +1460 } +1461 +1462 self.append(property); +1463 self.append(' : '); +1464 if (isGetter) { +1465 self.append('<getter>'); +1466 } else { +1467 self.format(obj[property]); +1468 } +1469 }); 1470 -1471 jasmine.StringPrettyPrinter.prototype.append = function(value) { -1472 this.string += value; -1473 }; -1474 jasmine.Queue = function(env) { -1475 this.env = env; -1476 this.blocks = []; -1477 this.running = false; -1478 this.index = 0; -1479 this.offset = 0; -1480 }; -1481 -1482 jasmine.Queue.prototype.addBefore = function (block) { -1483 this.blocks.unshift(block); -1484 }; -1485 -1486 jasmine.Queue.prototype.add = function(block) { -1487 this.blocks.push(block); -1488 }; -1489 -1490 jasmine.Queue.prototype.insertNext = function (block) { -1491 this.blocks.splice((this.index + this.offset + 1), 0, block); -1492 this.offset++; -1493 }; -1494 -1495 jasmine.Queue.prototype.start = function(onComplete) { -1496 var self = this; -1497 self.running = true; -1498 self.onComplete = onComplete; -1499 if (self.blocks[0]) { -1500 self.blocks[0].execute(function () { -1501 self._next(); -1502 }); -1503 } else { -1504 self.finish(); -1505 } +1471 this.append(' }'); +1472 }; +1473 +1474 jasmine.StringPrettyPrinter.prototype.append = function(value) { +1475 this.string += value; +1476 }; +1477 jasmine.Queue = function(env) { +1478 this.env = env; +1479 this.blocks = []; +1480 this.running = false; +1481 this.index = 0; +1482 this.offset = 0; +1483 }; +1484 +1485 jasmine.Queue.prototype.addBefore = function(block) { +1486 this.blocks.unshift(block); +1487 }; +1488 +1489 jasmine.Queue.prototype.add = function(block) { +1490 this.blocks.push(block); +1491 }; +1492 +1493 jasmine.Queue.prototype.insertNext = function(block) { +1494 this.blocks.splice((this.index + this.offset + 1), 0, block); +1495 this.offset++; +1496 }; +1497 +1498 jasmine.Queue.prototype.start = function(onComplete) { +1499 this.running = true; +1500 this.onComplete = onComplete; +1501 this.next_(); +1502 }; +1503 +1504 jasmine.Queue.prototype.isRunning = function() { +1505 return this.running; 1506 }; 1507 -1508 jasmine.Queue.prototype.isRunning = function () { -1509 return this.running; -1510 }; -1511 -1512 jasmine.Queue.prototype._next = function () { -1513 var self = this; -1514 var doNext = function () { -1515 self.offset = 0; -1516 self.index++; -1517 if (self.index < self.blocks.length) { -1518 self.blocks[self.index].execute(function () { -1519 self._next(); -1520 }); -1521 } else { -1522 self.finish(); -1523 } -1524 }; -1525 var now = new Date().getTime(); -1526 if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { -1527 this.env.lastUpdate = now; -1528 this.env.setTimeout(doNext, 0); -1529 } else { -1530 doNext(); -1531 } -1532 -1533 }; -1534 -1535 jasmine.Queue.prototype.finish = function () { -1536 this.running = false; -1537 if (this.onComplete) { -1538 this.onComplete(); -1539 } -1540 }; -1541 -1542 jasmine.Queue.prototype.results = function () { -1543 var results = new jasmine.NestedResults(); -1544 for (var i = 0; i < this.blocks.length; i++) { -1545 if (this.blocks[i].results) { -1546 results.addResult(this.blocks[i].results()); -1547 } -1548 } -1549 return results; -1550 }; -1551 -1552 -1553 /* JasmineReporters.reporter -1554 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to -1555 * descendants of this object to do something with the results (see json_reporter.js) -1556 */ -1557 jasmine.Reporters = {}; -1558 -1559 jasmine.Reporters.reporter = function(callbacks) { -1560 var that = { -1561 callbacks: callbacks || {}, -1562 -1563 doCallback: function(callback, results) { -1564 if (callback) { -1565 callback(results); -1566 } -1567 }, -1568 -1569 reportRunnerResults: function(runner) { -1570 that.doCallback(that.callbacks.runnerCallback, runner); -1571 }, -1572 reportSuiteResults: function(suite) { -1573 that.doCallback(that.callbacks.suiteCallback, suite); -1574 }, -1575 reportSpecResults: function(spec) { -1576 that.doCallback(that.callbacks.specCallback, spec); -1577 }, -1578 log: function (str) { -1579 if (console && console.log) console.log(str); -1580 } -1581 }; -1582 -1583 return that; -1584 }; -1585 -1586 /** -1587 * Runner -1588 * -1589 * @constructor -1590 * @param {jasmine.Env} env -1591 */ -1592 jasmine.Runner = function(env) { -1593 var self = this; -1594 self.env = env; -1595 self.queue = new jasmine.Queue(env); -1596 self.before_ = []; -1597 self.after_ = []; -1598 self.suites_ = []; -1599 }; +1508 jasmine.Queue.LOOP_DONT_RECURSE = true; +1509 +1510 jasmine.Queue.prototype.next_ = function() { +1511 var self = this; +1512 var goAgain = true; +1513 +1514 while (goAgain) { +1515 goAgain = false; +1516 +1517 if (self.index < self.blocks.length) { +1518 var calledSynchronously = true; +1519 var completedSynchronously = false; +1520 +1521 var onComplete = function () { +1522 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { +1523 completedSynchronously = true; +1524 return; +1525 } +1526 +1527 self.offset = 0; +1528 self.index++; +1529 +1530 var now = new Date().getTime(); +1531 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { +1532 self.env.lastUpdate = now; +1533 self.env.setTimeout(function() { +1534 self.next_(); +1535 }, 0); +1536 } else { +1537 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { +1538 goAgain = true; +1539 } else { +1540 self.next_(); +1541 } +1542 } +1543 }; +1544 self.blocks[self.index].execute(onComplete); +1545 +1546 calledSynchronously = false; +1547 if (completedSynchronously) { +1548 onComplete(); +1549 } +1550 +1551 } else { +1552 self.running = false; +1553 if (self.onComplete) { +1554 self.onComplete(); +1555 } +1556 } +1557 } +1558 }; +1559 +1560 jasmine.Queue.prototype.results = function() { +1561 var results = new jasmine.NestedResults(); +1562 for (var i = 0; i < this.blocks.length; i++) { +1563 if (this.blocks[i].results) { +1564 results.addResult(this.blocks[i].results()); +1565 } +1566 } +1567 return results; +1568 }; +1569 +1570 +1571 /* JasmineReporters.reporter +1572 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to +1573 * descendants of this object to do something with the results (see json_reporter.js) +1574 */ +1575 jasmine.Reporters = {}; +1576 +1577 jasmine.Reporters.reporter = function(callbacks) { +1578 var that = { +1579 callbacks: callbacks || {}, +1580 +1581 doCallback: function(callback, results) { +1582 if (callback) { +1583 callback(results); +1584 } +1585 }, +1586 +1587 reportRunnerResults: function(runner) { +1588 that.doCallback(that.callbacks.runnerCallback, runner); +1589 }, +1590 reportSuiteResults: function(suite) { +1591 that.doCallback(that.callbacks.suiteCallback, suite); +1592 }, +1593 reportSpecResults: function(spec) { +1594 that.doCallback(that.callbacks.specCallback, spec); +1595 }, +1596 log: function (str) { +1597 if (console && console.log) console.log(str); +1598 } +1599 }; 1600 -1601 jasmine.Runner.prototype.execute = function() { -1602 var self = this; -1603 if (self.env.reporter.reportRunnerStarting) { -1604 self.env.reporter.reportRunnerStarting(this); -1605 } -1606 self.queue.start(function () { -1607 self.finishCallback(); -1608 }); -1609 }; -1610 -1611 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { -1612 beforeEachFunction.typeName = 'beforeEach'; -1613 this.before_.push(beforeEachFunction); -1614 }; -1615 -1616 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { -1617 afterEachFunction.typeName = 'afterEach'; -1618 this.after_.push(afterEachFunction); -1619 }; -1620 -1621 -1622 jasmine.Runner.prototype.finishCallback = function() { -1623 this.env.reporter.reportRunnerResults(this); -1624 }; -1625 -1626 jasmine.Runner.prototype.addSuite = function(suite) { -1627 this.suites_.push(suite); -1628 }; -1629 -1630 jasmine.Runner.prototype.add = function(block) { -1631 if (block instanceof jasmine.Suite) { -1632 this.addSuite(block); -1633 } -1634 this.queue.add(block); -1635 }; -1636 -1637 /** @deprecated */ -1638 jasmine.Runner.prototype.getAllSuites = function() { -1639 return this.suites_; -1640 }; -1641 -1642 -1643 jasmine.Runner.prototype.suites = function() { -1644 return this.suites_; -1645 }; -1646 -1647 jasmine.Runner.prototype.results = function() { -1648 return this.queue.results(); -1649 }; -1650 -1651 /** @deprecated */ -1652 jasmine.Runner.prototype.getResults = function() { -1653 return this.queue.results(); -1654 }; -1655 /** -1656 * Internal representation of a Jasmine specification, or test. -1657 * -1658 * @constructor -1659 * @param {jasmine.Env} env -1660 * @param {jasmine.Suite} suite -1661 * @param {String} description -1662 */ -1663 jasmine.Spec = function(env, suite, description) { -1664 if (!env) { -1665 throw new Error('jasmine.Env() required'); -1666 } -1667 ; -1668 if (!suite) { -1669 throw new Error('jasmine.Suite() required'); -1670 } -1671 ; -1672 var spec = this; -1673 spec.id = env.nextSpecId ? env.nextSpecId() : null; -1674 spec.env = env; -1675 spec.suite = suite; -1676 spec.description = description; -1677 spec.queue = new jasmine.Queue(env); -1678 -1679 spec.afterCallbacks = []; -1680 spec.spies_ = []; -1681 -1682 spec.results_ = new jasmine.NestedResults(); -1683 spec.results_.description = description; -1684 spec.matchersClass = null; -1685 }; -1686 -1687 jasmine.Spec.prototype.getFullName = function() { -1688 return this.suite.getFullName() + ' ' + this.description + '.'; -1689 }; -1690 -1691 -1692 jasmine.Spec.prototype.results = function() { -1693 return this.results_; -1694 }; -1695 -1696 jasmine.Spec.prototype.log = function(message) { -1697 return this.results_.log(message); -1698 }; +1601 return that; +1602 }; +1603 +1604 /** +1605 * Runner +1606 * +1607 * @constructor +1608 * @param {jasmine.Env} env +1609 */ +1610 jasmine.Runner = function(env) { +1611 var self = this; +1612 self.env = env; +1613 self.queue = new jasmine.Queue(env); +1614 self.before_ = []; +1615 self.after_ = []; +1616 self.suites_ = []; +1617 }; +1618 +1619 jasmine.Runner.prototype.execute = function() { +1620 var self = this; +1621 if (self.env.reporter.reportRunnerStarting) { +1622 self.env.reporter.reportRunnerStarting(this); +1623 } +1624 self.queue.start(function () { +1625 self.finishCallback(); +1626 }); +1627 }; +1628 +1629 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { +1630 beforeEachFunction.typeName = 'beforeEach'; +1631 this.before_.push(beforeEachFunction); +1632 }; +1633 +1634 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { +1635 afterEachFunction.typeName = 'afterEach'; +1636 this.after_.push(afterEachFunction); +1637 }; +1638 +1639 +1640 jasmine.Runner.prototype.finishCallback = function() { +1641 this.env.reporter.reportRunnerResults(this); +1642 }; +1643 +1644 jasmine.Runner.prototype.addSuite = function(suite) { +1645 this.suites_.push(suite); +1646 }; +1647 +1648 jasmine.Runner.prototype.add = function(block) { +1649 if (block instanceof jasmine.Suite) { +1650 this.addSuite(block); +1651 } +1652 this.queue.add(block); +1653 }; +1654 +1655 /** @deprecated */ +1656 jasmine.Runner.prototype.getAllSuites = function() { +1657 return this.suites_; +1658 }; +1659 +1660 +1661 jasmine.Runner.prototype.suites = function() { +1662 return this.suites_; +1663 }; +1664 +1665 jasmine.Runner.prototype.results = function() { +1666 return this.queue.results(); +1667 }; +1668 +1669 /** @deprecated */ +1670 jasmine.Runner.prototype.getResults = function() { +1671 return this.queue.results(); +1672 }; +1673 /** +1674 * Internal representation of a Jasmine specification, or test. +1675 * +1676 * @constructor +1677 * @param {jasmine.Env} env +1678 * @param {jasmine.Suite} suite +1679 * @param {String} description +1680 */ +1681 jasmine.Spec = function(env, suite, description) { +1682 if (!env) { +1683 throw new Error('jasmine.Env() required'); +1684 } +1685 ; +1686 if (!suite) { +1687 throw new Error('jasmine.Suite() required'); +1688 } +1689 ; +1690 var spec = this; +1691 spec.id = env.nextSpecId ? env.nextSpecId() : null; +1692 spec.env = env; +1693 spec.suite = suite; +1694 spec.description = description; +1695 spec.queue = new jasmine.Queue(env); +1696 +1697 spec.afterCallbacks = []; +1698 spec.spies_ = []; 1699 -1700 /** @deprecated */ -1701 jasmine.Spec.prototype.getResults = function() { -1702 return this.results_; +1700 spec.results_ = new jasmine.NestedResults(); +1701 spec.results_.description = description; +1702 spec.matchersClass = null; 1703 }; 1704 -1705 jasmine.Spec.prototype.runs = function (func) { -1706 var block = new jasmine.Block(this.env, func, this); -1707 this.addToQueue(block); -1708 return this; -1709 }; -1710 -1711 jasmine.Spec.prototype.addToQueue = function (block) { -1712 if (this.queue.isRunning()) { -1713 this.queue.insertNext(block); -1714 } else { -1715 this.queue.add(block); -1716 } -1717 }; -1718 -1719 /** -1720 * @private -1721 * @deprecated -1722 */ -1723 jasmine.Spec.prototype.expects_that = function(actual) { -1724 return this.expect(actual); -1725 }; -1726 -1727 jasmine.Spec.prototype.expect = function(actual) { -1728 return new (this.getMatchersClass_())(this.env, actual, this.results_); -1729 }; -1730 -1731 jasmine.Spec.prototype.waits = function(timeout) { -1732 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); -1733 this.addToQueue(waitsFunc); -1734 return this; +1705 jasmine.Spec.prototype.getFullName = function() { +1706 return this.suite.getFullName() + ' ' + this.description + '.'; +1707 }; +1708 +1709 +1710 jasmine.Spec.prototype.results = function() { +1711 return this.results_; +1712 }; +1713 +1714 jasmine.Spec.prototype.log = function(message) { +1715 return this.results_.log(message); +1716 }; +1717 +1718 /** @deprecated */ +1719 jasmine.Spec.prototype.getResults = function() { +1720 return this.results_; +1721 }; +1722 +1723 jasmine.Spec.prototype.runs = function (func) { +1724 var block = new jasmine.Block(this.env, func, this); +1725 this.addToQueue(block); +1726 return this; +1727 }; +1728 +1729 jasmine.Spec.prototype.addToQueue = function (block) { +1730 if (this.queue.isRunning()) { +1731 this.queue.insertNext(block); +1732 } else { +1733 this.queue.add(block); +1734 } 1735 }; 1736 -1737 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { -1738 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); -1739 this.addToQueue(waitsForFunc); -1740 return this; -1741 }; -1742 -1743 jasmine.Spec.prototype.fail = function (e) { -1744 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); -1745 }; -1746 -1747 jasmine.Spec.prototype.getMatchersClass_ = function() { -1748 return this.matchersClass || jasmine.Matchers; -1749 }; -1750 -1751 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -1752 var parent = this.getMatchersClass_(); -1753 var newMatchersClass = function() { -1754 parent.apply(this, arguments); -1755 }; -1756 jasmine.util.inherit(newMatchersClass, parent); -1757 for (var method in matchersPrototype) { -1758 newMatchersClass.prototype[method] = matchersPrototype[method]; -1759 } -1760 this.matchersClass = newMatchersClass; -1761 }; -1762 -1763 jasmine.Spec.prototype.finishCallback = function() { -1764 this.env.reporter.reportSpecResults(this); -1765 }; -1766 -1767 jasmine.Spec.prototype.finish = function(onComplete) { -1768 this.removeAllSpies(); -1769 this.finishCallback(); -1770 if (onComplete) { -1771 onComplete(); -1772 } -1773 }; -1774 -1775 jasmine.Spec.prototype.after = function(doAfter, test) { -1776 -1777 if (this.queue.isRunning()) { -1778 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -1779 } else { -1780 this.afterCallbacks.unshift(doAfter); -1781 } -1782 }; -1783 -1784 jasmine.Spec.prototype.execute = function(onComplete) { -1785 var spec = this; -1786 if (!spec.env.specFilter(spec)) { -1787 spec.results_.skipped = true; -1788 spec.finish(onComplete); -1789 return; +1737 /** +1738 * @private +1739 * @deprecated +1740 */ +1741 jasmine.Spec.prototype.expects_that = function(actual) { +1742 return this.expect(actual); +1743 }; +1744 +1745 jasmine.Spec.prototype.expect = function(actual) { +1746 return new (this.getMatchersClass_())(this.env, actual, this.results_); +1747 }; +1748 +1749 jasmine.Spec.prototype.waits = function(timeout) { +1750 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); +1751 this.addToQueue(waitsFunc); +1752 return this; +1753 }; +1754 +1755 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { +1756 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); +1757 this.addToQueue(waitsForFunc); +1758 return this; +1759 }; +1760 +1761 jasmine.Spec.prototype.fail = function (e) { +1762 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); +1763 }; +1764 +1765 jasmine.Spec.prototype.getMatchersClass_ = function() { +1766 return this.matchersClass || jasmine.Matchers; +1767 }; +1768 +1769 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +1770 var parent = this.getMatchersClass_(); +1771 var newMatchersClass = function() { +1772 parent.apply(this, arguments); +1773 }; +1774 jasmine.util.inherit(newMatchersClass, parent); +1775 for (var method in matchersPrototype) { +1776 newMatchersClass.prototype[method] = matchersPrototype[method]; +1777 } +1778 this.matchersClass = newMatchersClass; +1779 }; +1780 +1781 jasmine.Spec.prototype.finishCallback = function() { +1782 this.env.reporter.reportSpecResults(this); +1783 }; +1784 +1785 jasmine.Spec.prototype.finish = function(onComplete) { +1786 this.removeAllSpies(); +1787 this.finishCallback(); +1788 if (onComplete) { +1789 onComplete(); 1790 } -1791 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +1791 }; 1792 -1793 spec.env.currentSpec = spec; -1794 spec.env.currentlyRunningTests = true; -1795 -1796 spec.addBeforesAndAftersToQueue(); -1797 -1798 spec.queue.start(function () { -1799 spec.finish(onComplete); -1800 }); -1801 spec.env.currentlyRunningTests = false; -1802 }; -1803 -1804 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -1805 var runner = this.env.currentRunner(); -1806 for (var suite = this.suite; suite; suite = suite.parentSuite) { -1807 for (var i = 0; i < suite.before_.length; i++) { -1808 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -1809 } -1810 } -1811 for (var i = 0; i < runner.before_.length; i++) { -1812 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -1813 } -1814 for (i = 0; i < this.afterCallbacks.length; i++) { -1815 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -1816 } -1817 for (suite = this.suite; suite; suite = suite.parentSuite) { -1818 for (var i = 0; i < suite.after_.length; i++) { -1819 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -1820 } -1821 } -1822 for (var i = 0; i < runner.after_.length; i++) { -1823 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -1824 } -1825 }; -1826 -1827 jasmine.Spec.prototype.explodes = function() { -1828 throw 'explodes function should not have been called'; -1829 }; -1830 -1831 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -1832 if (obj == undefined) { -1833 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1793 jasmine.Spec.prototype.after = function(doAfter, test) { +1794 +1795 if (this.queue.isRunning()) { +1796 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +1797 } else { +1798 this.afterCallbacks.unshift(doAfter); +1799 } +1800 }; +1801 +1802 jasmine.Spec.prototype.execute = function(onComplete) { +1803 var spec = this; +1804 if (!spec.env.specFilter(spec)) { +1805 spec.results_.skipped = true; +1806 spec.finish(onComplete); +1807 return; +1808 } +1809 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +1810 +1811 spec.env.currentSpec = spec; +1812 spec.env.currentlyRunningTests = true; +1813 +1814 spec.addBeforesAndAftersToQueue(); +1815 +1816 spec.queue.start(function () { +1817 spec.finish(onComplete); +1818 }); +1819 spec.env.currentlyRunningTests = false; +1820 }; +1821 +1822 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +1823 var runner = this.env.currentRunner(); +1824 for (var suite = this.suite; suite; suite = suite.parentSuite) { +1825 for (var i = 0; i < suite.before_.length; i++) { +1826 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +1827 } +1828 } +1829 for (var i = 0; i < runner.before_.length; i++) { +1830 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +1831 } +1832 for (i = 0; i < this.afterCallbacks.length; i++) { +1833 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); 1834 } -1835 -1836 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -1837 throw methodName + '() method does not exist'; -1838 } -1839 -1840 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -1841 throw new Error(methodName + ' has already been spied upon'); +1835 for (suite = this.suite; suite; suite = suite.parentSuite) { +1836 for (var i = 0; i < suite.after_.length; i++) { +1837 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +1838 } +1839 } +1840 for (var i = 0; i < runner.after_.length; i++) { +1841 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); 1842 } -1843 -1844 var spyObj = jasmine.createSpy(methodName); -1845 -1846 this.spies_.push(spyObj); -1847 spyObj.baseObj = obj; -1848 spyObj.methodName = methodName; -1849 spyObj.originalValue = obj[methodName]; -1850 -1851 obj[methodName] = spyObj; -1852 -1853 return spyObj; -1854 }; -1855 -1856 jasmine.Spec.prototype.removeAllSpies = function() { -1857 for (var i = 0; i < this.spies_.length; i++) { -1858 var spy = this.spies_[i]; -1859 spy.baseObj[spy.methodName] = spy.originalValue; +1843 }; +1844 +1845 jasmine.Spec.prototype.explodes = function() { +1846 throw 'explodes function should not have been called'; +1847 }; +1848 +1849 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +1850 if (obj == undefined) { +1851 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1852 } +1853 +1854 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { +1855 throw methodName + '() method does not exist'; +1856 } +1857 +1858 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +1859 throw new Error(methodName + ' has already been spied upon'); 1860 } -1861 this.spies_ = []; -1862 }; +1861 +1862 var spyObj = jasmine.createSpy(methodName); 1863 -1864 /** -1865 * Internal representation of a Jasmine suite. -1866 * -1867 * @constructor -1868 * @param {jasmine.Env} env -1869 * @param {String} description -1870 * @param {Function} specDefinitions -1871 * @param {jasmine.Suite} parentSuite -1872 */ -1873 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { -1874 var self = this; -1875 self.id = env.nextSuiteId ? env.nextSuiteId() : null; -1876 self.description = description; -1877 self.queue = new jasmine.Queue(env); -1878 self.parentSuite = parentSuite; -1879 self.env = env; -1880 self.before_ = []; -1881 self.after_ = []; -1882 self.specs_ = []; -1883 }; -1884 -1885 jasmine.Suite.prototype.getFullName = function() { -1886 var fullName = this.description; -1887 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { -1888 fullName = parentSuite.description + ' ' + fullName; -1889 } -1890 return fullName; -1891 }; -1892 -1893 jasmine.Suite.prototype.finish = function(onComplete) { -1894 this.env.reporter.reportSuiteResults(this); -1895 this.finished = true; -1896 if (typeof(onComplete) == 'function') { -1897 onComplete(); -1898 } -1899 }; -1900 -1901 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { -1902 beforeEachFunction.typeName = 'beforeEach'; -1903 this.before_.push(beforeEachFunction); -1904 }; -1905 -1906 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { -1907 afterEachFunction.typeName = 'afterEach'; -1908 this.after_.push(afterEachFunction); +1864 this.spies_.push(spyObj); +1865 spyObj.baseObj = obj; +1866 spyObj.methodName = methodName; +1867 spyObj.originalValue = obj[methodName]; +1868 +1869 obj[methodName] = spyObj; +1870 +1871 return spyObj; +1872 }; +1873 +1874 jasmine.Spec.prototype.removeAllSpies = function() { +1875 for (var i = 0; i < this.spies_.length; i++) { +1876 var spy = this.spies_[i]; +1877 spy.baseObj[spy.methodName] = spy.originalValue; +1878 } +1879 this.spies_ = []; +1880 }; +1881 +1882 /** +1883 * Internal representation of a Jasmine suite. +1884 * +1885 * @constructor +1886 * @param {jasmine.Env} env +1887 * @param {String} description +1888 * @param {Function} specDefinitions +1889 * @param {jasmine.Suite} parentSuite +1890 */ +1891 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { +1892 var self = this; +1893 self.id = env.nextSuiteId ? env.nextSuiteId() : null; +1894 self.description = description; +1895 self.queue = new jasmine.Queue(env); +1896 self.parentSuite = parentSuite; +1897 self.env = env; +1898 self.before_ = []; +1899 self.after_ = []; +1900 self.specs_ = []; +1901 }; +1902 +1903 jasmine.Suite.prototype.getFullName = function() { +1904 var fullName = this.description; +1905 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { +1906 fullName = parentSuite.description + ' ' + fullName; +1907 } +1908 return fullName; 1909 }; 1910 -1911 /** @deprecated */ -1912 jasmine.Suite.prototype.getResults = function() { -1913 return this.queue.results(); -1914 }; -1915 -1916 jasmine.Suite.prototype.results = function() { -1917 return this.queue.results(); -1918 }; -1919 -1920 jasmine.Suite.prototype.add = function(block) { -1921 if (block instanceof jasmine.Suite) { -1922 this.env.currentRunner().addSuite(block); -1923 } else { -1924 this.specs_.push(block); -1925 } -1926 this.queue.add(block); +1911 jasmine.Suite.prototype.finish = function(onComplete) { +1912 this.env.reporter.reportSuiteResults(this); +1913 this.finished = true; +1914 if (typeof(onComplete) == 'function') { +1915 onComplete(); +1916 } +1917 }; +1918 +1919 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { +1920 beforeEachFunction.typeName = 'beforeEach'; +1921 this.before_.push(beforeEachFunction); +1922 }; +1923 +1924 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { +1925 afterEachFunction.typeName = 'afterEach'; +1926 this.after_.push(afterEachFunction); 1927 }; 1928 1929 /** @deprecated */ -1930 jasmine.Suite.prototype.specCount = function() { -1931 return this.specs_.length; +1930 jasmine.Suite.prototype.getResults = function() { +1931 return this.queue.results(); 1932 }; 1933 -1934 jasmine.Suite.prototype.specs = function() { -1935 return this.specs_; +1934 jasmine.Suite.prototype.results = function() { +1935 return this.queue.results(); 1936 }; 1937 -1938 jasmine.Suite.prototype.execute = function(onComplete) { -1939 var self = this; -1940 this.queue.start(function () { -1941 self.finish(onComplete); -1942 }); -1943 }; -1944 jasmine.WaitsBlock = function(env, timeout, spec) { -1945 this.timeout = timeout; -1946 jasmine.Block.call(this, env, null, spec); -1947 }; -1948 -1949 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); -1950 -1951 jasmine.WaitsBlock.prototype.execute = function (onComplete) { -1952 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); -1953 this.env.setTimeout(function () { -1954 onComplete(); -1955 }, this.timeout); -1956 }; -1957 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { -1958 this.timeout = timeout; -1959 this.latchFunction = latchFunction; -1960 this.message = message; -1961 this.totalTimeSpentWaitingForLatch = 0; -1962 jasmine.Block.call(this, env, null, spec); -1963 }; -1964 -1965 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +1938 jasmine.Suite.prototype.add = function(block) { +1939 if (block instanceof jasmine.Suite) { +1940 this.env.currentRunner().addSuite(block); +1941 } else { +1942 this.specs_.push(block); +1943 } +1944 this.queue.add(block); +1945 }; +1946 +1947 /** @deprecated */ +1948 jasmine.Suite.prototype.specCount = function() { +1949 return this.specs_.length; +1950 }; +1951 +1952 jasmine.Suite.prototype.specs = function() { +1953 return this.specs_; +1954 }; +1955 +1956 jasmine.Suite.prototype.execute = function(onComplete) { +1957 var self = this; +1958 this.queue.start(function () { +1959 self.finish(onComplete); +1960 }); +1961 }; +1962 jasmine.WaitsBlock = function(env, timeout, spec) { +1963 this.timeout = timeout; +1964 jasmine.Block.call(this, env, null, spec); +1965 }; 1966 -1967 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +1967 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); 1968 -1969 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { -1970 var self = this; -1971 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); -1972 var latchFunctionResult; -1973 try { -1974 latchFunctionResult = self.latchFunction.apply(self.spec); -1975 } catch (e) { -1976 self.spec.fail(e); -1977 onComplete(); -1978 return; -1979 } -1980 -1981 if (latchFunctionResult) { -1982 onComplete(); -1983 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { -1984 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); -1985 self.spec.fail({ -1986 name: 'timeout', -1987 message: message -1988 }); -1989 self.spec._next(); -1990 } else { -1991 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; -1992 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); -1993 } -1994 }; -1995 // Mock setTimeout, clearTimeout -1996 // Contributed by Pivotal Computer Systems, www.pivotalsf.com -1997 -1998 jasmine.FakeTimer = function() { -1999 this.reset(); -2000 -2001 var self = this; -2002 self.setTimeout = function(funcToCall, millis) { -2003 self.timeoutsMade++; -2004 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); -2005 return self.timeoutsMade; -2006 }; -2007 -2008 self.setInterval = function(funcToCall, millis) { -2009 self.timeoutsMade++; -2010 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); -2011 return self.timeoutsMade; -2012 }; -2013 -2014 self.clearTimeout = function(timeoutKey) { -2015 self.scheduledFunctions[timeoutKey] = undefined; -2016 }; -2017 -2018 self.clearInterval = function(timeoutKey) { -2019 self.scheduledFunctions[timeoutKey] = undefined; -2020 }; -2021 -2022 }; -2023 -2024 jasmine.FakeTimer.prototype.reset = function() { -2025 this.timeoutsMade = 0; -2026 this.scheduledFunctions = {}; -2027 this.nowMillis = 0; -2028 }; -2029 -2030 jasmine.FakeTimer.prototype.tick = function(millis) { -2031 var oldMillis = this.nowMillis; -2032 var newMillis = oldMillis + millis; -2033 this.runFunctionsWithinRange(oldMillis, newMillis); -2034 this.nowMillis = newMillis; -2035 }; -2036 -2037 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { -2038 var scheduledFunc; -2039 var funcsToRun = []; -2040 for (var timeoutKey in this.scheduledFunctions) { -2041 scheduledFunc = this.scheduledFunctions[timeoutKey]; -2042 if (scheduledFunc != undefined && -2043 scheduledFunc.runAtMillis >= oldMillis && -2044 scheduledFunc.runAtMillis <= nowMillis) { -2045 funcsToRun.push(scheduledFunc); -2046 this.scheduledFunctions[timeoutKey] = undefined; -2047 } -2048 } -2049 -2050 if (funcsToRun.length > 0) { -2051 funcsToRun.sort(function(a, b) { -2052 return a.runAtMillis - b.runAtMillis; -2053 }); -2054 for (var i = 0; i < funcsToRun.length; ++i) { -2055 try { -2056 var funcToRun = funcsToRun[i]; -2057 this.nowMillis = funcToRun.runAtMillis; -2058 funcToRun.funcToCall(); -2059 if (funcToRun.recurring) { -2060 this.scheduleFunction(funcToRun.timeoutKey, -2061 funcToRun.funcToCall, -2062 funcToRun.millis, -2063 true); -2064 } -2065 } catch(e) { -2066 } -2067 } -2068 this.runFunctionsWithinRange(oldMillis, nowMillis); -2069 } -2070 }; -2071 -2072 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { -2073 this.scheduledFunctions[timeoutKey] = { -2074 runAtMillis: this.nowMillis + millis, -2075 funcToCall: funcToCall, -2076 recurring: recurring, -2077 timeoutKey: timeoutKey, -2078 millis: millis -2079 }; -2080 }; -2081 -2082 -2083 jasmine.Clock = { -2084 defaultFakeTimer: new jasmine.FakeTimer(), -2085 -2086 reset: function() { -2087 jasmine.Clock.assertInstalled(); -2088 jasmine.Clock.defaultFakeTimer.reset(); -2089 }, -2090 -2091 tick: function(millis) { -2092 jasmine.Clock.assertInstalled(); -2093 jasmine.Clock.defaultFakeTimer.tick(millis); -2094 }, -2095 -2096 runFunctionsWithinRange: function(oldMillis, nowMillis) { -2097 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); -2098 }, +1969 jasmine.WaitsBlock.prototype.execute = function (onComplete) { +1970 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); +1971 this.env.setTimeout(function () { +1972 onComplete(); +1973 }, this.timeout); +1974 }; +1975 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { +1976 this.timeout = timeout; +1977 this.latchFunction = latchFunction; +1978 this.message = message; +1979 this.totalTimeSpentWaitingForLatch = 0; +1980 jasmine.Block.call(this, env, null, spec); +1981 }; +1982 +1983 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +1984 +1985 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +1986 +1987 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { +1988 var self = this; +1989 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); +1990 var latchFunctionResult; +1991 try { +1992 latchFunctionResult = self.latchFunction.apply(self.spec); +1993 } catch (e) { +1994 self.spec.fail(e); +1995 onComplete(); +1996 return; +1997 } +1998 +1999 if (latchFunctionResult) { +2000 onComplete(); +2001 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { +2002 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); +2003 self.spec.fail({ +2004 name: 'timeout', +2005 message: message +2006 }); +2007 self.spec._next(); +2008 } else { +2009 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; +2010 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); +2011 } +2012 }; +2013 // Mock setTimeout, clearTimeout +2014 // Contributed by Pivotal Computer Systems, www.pivotalsf.com +2015 +2016 jasmine.FakeTimer = function() { +2017 this.reset(); +2018 +2019 var self = this; +2020 self.setTimeout = function(funcToCall, millis) { +2021 self.timeoutsMade++; +2022 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); +2023 return self.timeoutsMade; +2024 }; +2025 +2026 self.setInterval = function(funcToCall, millis) { +2027 self.timeoutsMade++; +2028 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); +2029 return self.timeoutsMade; +2030 }; +2031 +2032 self.clearTimeout = function(timeoutKey) { +2033 self.scheduledFunctions[timeoutKey] = undefined; +2034 }; +2035 +2036 self.clearInterval = function(timeoutKey) { +2037 self.scheduledFunctions[timeoutKey] = undefined; +2038 }; +2039 +2040 }; +2041 +2042 jasmine.FakeTimer.prototype.reset = function() { +2043 this.timeoutsMade = 0; +2044 this.scheduledFunctions = {}; +2045 this.nowMillis = 0; +2046 }; +2047 +2048 jasmine.FakeTimer.prototype.tick = function(millis) { +2049 var oldMillis = this.nowMillis; +2050 var newMillis = oldMillis + millis; +2051 this.runFunctionsWithinRange(oldMillis, newMillis); +2052 this.nowMillis = newMillis; +2053 }; +2054 +2055 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { +2056 var scheduledFunc; +2057 var funcsToRun = []; +2058 for (var timeoutKey in this.scheduledFunctions) { +2059 scheduledFunc = this.scheduledFunctions[timeoutKey]; +2060 if (scheduledFunc != undefined && +2061 scheduledFunc.runAtMillis >= oldMillis && +2062 scheduledFunc.runAtMillis <= nowMillis) { +2063 funcsToRun.push(scheduledFunc); +2064 this.scheduledFunctions[timeoutKey] = undefined; +2065 } +2066 } +2067 +2068 if (funcsToRun.length > 0) { +2069 funcsToRun.sort(function(a, b) { +2070 return a.runAtMillis - b.runAtMillis; +2071 }); +2072 for (var i = 0; i < funcsToRun.length; ++i) { +2073 try { +2074 var funcToRun = funcsToRun[i]; +2075 this.nowMillis = funcToRun.runAtMillis; +2076 funcToRun.funcToCall(); +2077 if (funcToRun.recurring) { +2078 this.scheduleFunction(funcToRun.timeoutKey, +2079 funcToRun.funcToCall, +2080 funcToRun.millis, +2081 true); +2082 } +2083 } catch(e) { +2084 } +2085 } +2086 this.runFunctionsWithinRange(oldMillis, nowMillis); +2087 } +2088 }; +2089 +2090 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { +2091 this.scheduledFunctions[timeoutKey] = { +2092 runAtMillis: this.nowMillis + millis, +2093 funcToCall: funcToCall, +2094 recurring: recurring, +2095 timeoutKey: timeoutKey, +2096 millis: millis +2097 }; +2098 }; 2099 -2100 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { -2101 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); -2102 }, +2100 +2101 jasmine.Clock = { +2102 defaultFakeTimer: new jasmine.FakeTimer(), 2103 -2104 useMock: function() { -2105 var spec = jasmine.getEnv().currentSpec; -2106 spec.after(jasmine.Clock.uninstallMock); -2107 -2108 jasmine.Clock.installMock(); -2109 }, -2110 -2111 installMock: function() { -2112 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; -2113 }, -2114 -2115 uninstallMock: function() { -2116 jasmine.Clock.assertInstalled(); -2117 jasmine.Clock.installed = jasmine.Clock.real; -2118 }, -2119 -2120 real: { -2121 setTimeout: window.setTimeout, -2122 clearTimeout: window.clearTimeout, -2123 setInterval: window.setInterval, -2124 clearInterval: window.clearInterval -2125 }, -2126 -2127 assertInstalled: function() { -2128 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { -2129 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -2130 } -2131 }, +2104 reset: function() { +2105 jasmine.Clock.assertInstalled(); +2106 jasmine.Clock.defaultFakeTimer.reset(); +2107 }, +2108 +2109 tick: function(millis) { +2110 jasmine.Clock.assertInstalled(); +2111 jasmine.Clock.defaultFakeTimer.tick(millis); +2112 }, +2113 +2114 runFunctionsWithinRange: function(oldMillis, nowMillis) { +2115 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); +2116 }, +2117 +2118 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { +2119 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); +2120 }, +2121 +2122 useMock: function() { +2123 var spec = jasmine.getEnv().currentSpec; +2124 spec.after(jasmine.Clock.uninstallMock); +2125 +2126 jasmine.Clock.installMock(); +2127 }, +2128 +2129 installMock: function() { +2130 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; +2131 }, 2132 -2133 installed: null -2134 }; -2135 jasmine.Clock.installed = jasmine.Clock.real; -2136 -2137 window.setTimeout = function(funcToCall, millis) { -2138 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -2139 }; -2140 -2141 window.setInterval = function(funcToCall, millis) { -2142 return jasmine.Clock.installed.setInterval.apply(this, arguments); -2143 }; +2133 uninstallMock: function() { +2134 jasmine.Clock.assertInstalled(); +2135 jasmine.Clock.installed = jasmine.Clock.real; +2136 }, +2137 +2138 real: { +2139 setTimeout: window.setTimeout, +2140 clearTimeout: window.clearTimeout, +2141 setInterval: window.setInterval, +2142 clearInterval: window.clearInterval +2143 }, 2144 -2145 window.clearTimeout = function(timeoutKey) { -2146 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -2147 }; -2148 -2149 window.clearInterval = function(timeoutKey) { -2150 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -2151 }; -2152 -2153 \ No newline at end of file +2145 assertInstalled: function() { +2146 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { +2147 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); +2148 } +2149 }, +2150 +2151 installed: null +2152 }; +2153 jasmine.Clock.installed = jasmine.Clock.real; +2154 +2155 window.setTimeout = function(funcToCall, millis) { +2156 return jasmine.Clock.installed.setTimeout.apply(this, arguments); +2157 }; +2158 +2159 window.setInterval = function(funcToCall, millis) { +2160 return jasmine.Clock.installed.setInterval.apply(this, arguments); +2161 }; +2162 +2163 window.clearTimeout = function(timeoutKey) { +2164 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +2165 }; +2166 +2167 window.clearInterval = function(timeoutKey) { +2168 return jasmine.Clock.installed.clearInterval.apply(this, arguments); +2169 }; +2170 +2171 \ No newline at end of file diff --git a/lib/jasmine-0.9.0.js b/lib/jasmine-0.9.0.js index c44d73a..3e8825a 100644 --- a/lib/jasmine-0.9.0.js +++ b/lib/jasmine-0.9.0.js @@ -12,6 +12,12 @@ jasmine.unimplementedMethod_ = function() { throw new Error("unimplemented method"); }; +/** + * Large or small values here may result in slow test running & "Too much recursion" errors + * + */ +jasmine.UPDATE_INTERVAL = 250; + /** * Allows for bound functions to be comapred. Internal use only. * @@ -183,6 +189,7 @@ jasmine.Spy = function(name) { * mySpy.argsForCall[1] = [7, 8]; */ this.argsForCall = []; + this.calls = []; }; /** @@ -277,6 +284,7 @@ jasmine.Spy.prototype.reset = function() { this.wasCalled = false; this.callCount = 0; this.argsForCall = []; + this.calls = []; this.mostRecentCall = {}; }; @@ -286,13 +294,10 @@ jasmine.createSpy = function(name) { spyObj.wasCalled = true; spyObj.callCount++; var args = jasmine.util.argsToArray(arguments); - //spyObj.mostRecentCall = { - // object: this, - // args: args - //}; spyObj.mostRecentCall.object = this; spyObj.mostRecentCall.args = args; spyObj.argsForCall.push(args); + spyObj.calls.push({object: this, args: args}); return spyObj.plan.apply(this, arguments); }; @@ -517,7 +522,7 @@ jasmine.version_= { "major": 0, "minor": 9, "build": 0, - "revision": 1254287286 + "revision": 1255470394 }; /** * @namespace @@ -591,9 +596,7 @@ jasmine.Env = function() { this.reporter = new jasmine.MultiReporter(); - this.updateInterval = 0; - - this.updateInterval = 0; + this.updateInterval = jasmine.UPDATE_INTERVAL this.lastUpdate = 0; this.specFilter = function() { return true; @@ -1479,7 +1482,7 @@ jasmine.Queue = function(env) { this.offset = 0; }; -jasmine.Queue.prototype.addBefore = function (block) { +jasmine.Queue.prototype.addBefore = function(block) { this.blocks.unshift(block); }; @@ -1487,59 +1490,74 @@ jasmine.Queue.prototype.add = function(block) { this.blocks.push(block); }; -jasmine.Queue.prototype.insertNext = function (block) { +jasmine.Queue.prototype.insertNext = function(block) { this.blocks.splice((this.index + this.offset + 1), 0, block); this.offset++; }; jasmine.Queue.prototype.start = function(onComplete) { - var self = this; - self.running = true; - self.onComplete = onComplete; - if (self.blocks[0]) { - self.blocks[0].execute(function () { - self._next(); - }); - } else { - self.finish(); - } + this.running = true; + this.onComplete = onComplete; + this.next_(); }; -jasmine.Queue.prototype.isRunning = function () { +jasmine.Queue.prototype.isRunning = function() { return this.running; }; -jasmine.Queue.prototype._next = function () { +jasmine.Queue.LOOP_DONT_RECURSE = true; + +jasmine.Queue.prototype.next_ = function() { var self = this; - var doNext = function () { - self.offset = 0; - self.index++; + var goAgain = true; + + while (goAgain) { + goAgain = false; + if (self.index < self.blocks.length) { - self.blocks[self.index].execute(function () { - self._next(); - }); + var calledSynchronously = true; + var completedSynchronously = false; + + var onComplete = function () { + if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { + completedSynchronously = true; + return; + } + + self.offset = 0; + self.index++; + + var now = new Date().getTime(); + if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { + self.env.lastUpdate = now; + self.env.setTimeout(function() { + self.next_(); + }, 0); + } else { + if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { + goAgain = true; + } else { + self.next_(); + } + } + }; + self.blocks[self.index].execute(onComplete); + + calledSynchronously = false; + if (completedSynchronously) { + onComplete(); + } + } else { - self.finish(); + self.running = false; + if (self.onComplete) { + self.onComplete(); + } } - }; - var now = new Date().getTime(); - if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { - this.env.lastUpdate = now; - this.env.setTimeout(doNext, 0); - } else { - doNext(); - } - -}; - -jasmine.Queue.prototype.finish = function () { - this.running = false; - if (this.onComplete) { - this.onComplete(); } }; -jasmine.Queue.prototype.results = function () { +jasmine.Queue.prototype.results = function() { var results = new jasmine.NestedResults(); for (var i = 0; i < this.blocks.length; i++) { if (this.blocks[i].results) { diff --git a/spec/runner.html b/spec/runner.html new file mode 100644 index 0000000..f963bb4 --- /dev/null +++ b/spec/runner.html @@ -0,0 +1,76 @@ + + + + Jasmine Test Runner + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spec/suites/EnvSpec.js b/spec/suites/EnvSpec.js index 833c24f..cd6aa8f 100644 --- a/spec/suites/EnvSpec.js +++ b/spec/suites/EnvSpec.js @@ -1,10 +1,12 @@ describe("jasmine.Env", function() { + var env; + beforeEach(function() { + env = new jasmine.Env(); + env.updateInterval = 0; + }); describe('ids', function () { - var env; - beforeEach(function() { - env = new jasmine.Env(); - }); + it('nextSpecId should return consecutive integers, starting at 0', function () { expect(env.nextSpecId()).toEqual(0); expect(env.nextSpecId()).toEqual(1); @@ -18,11 +20,9 @@ describe("jasmine.Env", function() { }); }); describe("reporting", function() { - var env; var fakeReporter; beforeEach(function() { - env = new jasmine.Env(); fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]); }); @@ -36,7 +36,7 @@ describe("jasmine.Env", function() { afterEach(function () { jasmine.version_ = oldVersion; }); - + it('should raise an error if version is not set', function () { jasmine.version_ = null; var exception; diff --git a/spec/suites/ExceptionsSpec.js b/spec/suites/ExceptionsSpec.js index 04f4917..0be6a6c 100644 --- a/spec/suites/ExceptionsSpec.js +++ b/spec/suites/ExceptionsSpec.js @@ -3,6 +3,7 @@ describe('Exceptions:', function() { beforeEach(function() { env = new jasmine.Env(); + env.updateInterval = 0; }); it('jasmine.formatException formats Firefox exception maessages as expected', function() { diff --git a/spec/suites/JsApiReporterSpec.js b/spec/suites/JsApiReporterSpec.js index ab29b1e..6615fe5 100644 --- a/spec/suites/JsApiReporterSpec.js +++ b/spec/suites/JsApiReporterSpec.js @@ -6,6 +6,7 @@ describe('jasmine.jsApiReporter', function() { beforeEach(function() { var env = new jasmine.Env(); + env.updateInterval = 0; var suite = new jasmine.Suite(env); spec1 = new jasmine.Spec(env, suite, 'spec 1'); spec1.runs(function () { diff --git a/spec/suites/MatchersSpec.js b/spec/suites/MatchersSpec.js index 7ea452a..1682983 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -3,6 +3,7 @@ describe("jasmine.Matchers", function() { beforeEach(function() { env = new jasmine.Env(); + env.updateInterval = 0; }); function match(value) { diff --git a/spec/suites/QueueSpec.js b/spec/suites/QueueSpec.js new file mode 100644 index 0000000..59a70f3 --- /dev/null +++ b/spec/suites/QueueSpec.js @@ -0,0 +1,23 @@ +describe("jasmine.Queue", function() { + it("should not call itself recursively, so we don't get stack overflow errors", function() { + var queue = new jasmine.Queue(new jasmine.Env()); + queue.add(new jasmine.Block(null, function() {})); + queue.add(new jasmine.Block(null, function() {})); + queue.add(new jasmine.Block(null, function() {})); + queue.add(new jasmine.Block(null, function() {})); + + var nestCount = 0; + var maxNestCount = 0; + var nextCallCount = 0; + queue.next_ = function() { + nestCount++; + if (nestCount > maxNestCount) maxNestCount = nestCount; + + jasmine.Queue.prototype.next_.apply(queue, arguments); + nestCount--; + }; + + queue.start(); + expect(maxNestCount).toEqual(1); + }); +}); \ No newline at end of file diff --git a/spec/suites/ReporterSpec.js b/spec/suites/ReporterSpec.js index 95ba01d..4020530 100644 --- a/spec/suites/ReporterSpec.js +++ b/spec/suites/ReporterSpec.js @@ -4,7 +4,7 @@ describe('jasmine.Reporter', function() { beforeEach(function() { env = new jasmine.Env(); - + env.updateInterval = 0; }); it('should get called from the test runner', function() { diff --git a/spec/suites/RunnerSpec.js b/spec/suites/RunnerSpec.js index b2e4843..319b6af 100644 --- a/spec/suites/RunnerSpec.js +++ b/spec/suites/RunnerSpec.js @@ -4,6 +4,7 @@ describe('RunnerTest', function() { beforeEach(function() { env = new jasmine.Env(); + env.updateInterval = 0; fakeTimer = new jasmine.FakeTimer(); env.setTimeout = fakeTimer.setTimeout; diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index e35ad32..b00955b 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -4,6 +4,7 @@ describe("jasmine spec running", function () { beforeEach(function() { env = new jasmine.Env(); + env.updateInterval = 0; fakeTimer = new jasmine.FakeTimer(); env.setTimeout = fakeTimer.setTimeout; diff --git a/spec/suites/SpecSpec.js b/spec/suites/SpecSpec.js index ba060ef..de6640d 100644 --- a/spec/suites/SpecSpec.js +++ b/spec/suites/SpecSpec.js @@ -2,6 +2,7 @@ describe('Spec', function () { var env, suite; beforeEach(function() { env = new jasmine.Env(); + env.updateInterval = 0; suite = new jasmine.Suite(env, 'suite 1'); }); @@ -76,34 +77,34 @@ describe('Spec', function () { }); describe('results.passed', function () { - it('is true if all spec expectations pass', function () { - spec.runs(function () { - this.expect(true).toEqual(true); + it('is true if all spec expectations pass', function () { + spec.runs(function () { + this.expect(true).toEqual(true); + }); + spec.execute(); + expect(results.passed()).toEqual(true); }); - spec.execute(); - expect(results.passed()).toEqual(true); - }); it('is false if one spec expectation fails', function () { - spec.runs(function () { - this.expect(true).toEqual(false); + spec.runs(function () { + this.expect(true).toEqual(false); + }); + spec.execute(); + expect(results.passed()).toEqual(false); }); - spec.execute(); - expect(results.passed()).toEqual(false); - }); - it('a spec with no expectations will return true', function () { - var specWithoutExpectations = new jasmine.Spec(env, suite); - specWithoutExpectations.runs(function() { + it('a spec with no expectations will return true', function () { + var specWithoutExpectations = new jasmine.Spec(env, suite); + specWithoutExpectations.runs(function() { + }); + specWithoutExpectations.execute(); + expect(results.passed()).toEqual(true); }); - specWithoutExpectations.execute(); - expect(results.passed()).toEqual(true); - }); - it('an unexecuted spec will return true', function () { - expect(results.passed()).toEqual(true); - }); + it('an unexecuted spec will return true', function () { + expect(results.passed()).toEqual(true); + }); }); }); }); \ No newline at end of file diff --git a/spec/suites/SuiteSpec.js b/spec/suites/SuiteSpec.js index 58e2d48..f426b6a 100644 --- a/spec/suites/SuiteSpec.js +++ b/spec/suites/SuiteSpec.js @@ -4,6 +4,7 @@ describe('Suite', function() { beforeEach(function() { env = new jasmine.Env(); + env.updateInterval = 0; fakeTimer = new jasmine.FakeTimer(); env.setTimeout = fakeTimer.setTimeout; diff --git a/src/Env.js b/src/Env.js index 60842ec..3c3e0ab 100644 --- a/src/Env.js +++ b/src/Env.js @@ -11,9 +11,7 @@ jasmine.Env = function() { this.reporter = new jasmine.MultiReporter(); - this.updateInterval = 0; - - this.updateInterval = 0; + this.updateInterval = jasmine.UPDATE_INTERVAL this.lastUpdate = 0; this.specFilter = function() { return true; diff --git a/src/Queue.js b/src/Queue.js index 27d3737..c3e064a 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -6,7 +6,7 @@ jasmine.Queue = function(env) { this.offset = 0; }; -jasmine.Queue.prototype.addBefore = function (block) { +jasmine.Queue.prototype.addBefore = function(block) { this.blocks.unshift(block); }; @@ -14,59 +14,74 @@ jasmine.Queue.prototype.add = function(block) { this.blocks.push(block); }; -jasmine.Queue.prototype.insertNext = function (block) { +jasmine.Queue.prototype.insertNext = function(block) { this.blocks.splice((this.index + this.offset + 1), 0, block); this.offset++; }; jasmine.Queue.prototype.start = function(onComplete) { - var self = this; - self.running = true; - self.onComplete = onComplete; - if (self.blocks[0]) { - self.blocks[0].execute(function () { - self._next(); - }); - } else { - self.finish(); - } + this.running = true; + this.onComplete = onComplete; + this.next_(); }; -jasmine.Queue.prototype.isRunning = function () { +jasmine.Queue.prototype.isRunning = function() { return this.running; }; -jasmine.Queue.prototype._next = function () { +jasmine.Queue.LOOP_DONT_RECURSE = true; + +jasmine.Queue.prototype.next_ = function() { var self = this; - var doNext = function () { - self.offset = 0; - self.index++; + var goAgain = true; + + while (goAgain) { + goAgain = false; + if (self.index < self.blocks.length) { - self.blocks[self.index].execute(function () { - self._next(); - }); + var calledSynchronously = true; + var completedSynchronously = false; + + var onComplete = function () { + if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { + completedSynchronously = true; + return; + } + + self.offset = 0; + self.index++; + + var now = new Date().getTime(); + if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { + self.env.lastUpdate = now; + self.env.setTimeout(function() { + self.next_(); + }, 0); + } else { + if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { + goAgain = true; + } else { + self.next_(); + } + } + }; + self.blocks[self.index].execute(onComplete); + + calledSynchronously = false; + if (completedSynchronously) { + onComplete(); + } + } else { - self.finish(); + self.running = false; + if (self.onComplete) { + self.onComplete(); + } } - }; - var now = new Date().getTime(); - if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { - this.env.lastUpdate = now; - this.env.setTimeout(doNext, 0); - } else { - doNext(); - } - -}; - -jasmine.Queue.prototype.finish = function () { - this.running = false; - if (this.onComplete) { - this.onComplete(); } }; -jasmine.Queue.prototype.results = function () { +jasmine.Queue.prototype.results = function() { var results = new jasmine.NestedResults(); for (var i = 0; i < this.blocks.length; i++) { if (this.blocks[i].results) { diff --git a/src/base.js b/src/base.js index ce0afd3..682438a 100755 --- a/src/base.js +++ b/src/base.js @@ -12,6 +12,12 @@ jasmine.unimplementedMethod_ = function() { throw new Error("unimplemented method"); }; +/** + * Large or small values here may result in slow test running & "Too much recursion" errors + * + */ +jasmine.UPDATE_INTERVAL = 250; + /** * Allows for bound functions to be comapred. Internal use only. * @@ -183,6 +189,7 @@ jasmine.Spy = function(name) { * mySpy.argsForCall[1] = [7, 8]; */ this.argsForCall = []; + this.calls = []; }; /** @@ -277,6 +284,7 @@ jasmine.Spy.prototype.reset = function() { this.wasCalled = false; this.callCount = 0; this.argsForCall = []; + this.calls = []; this.mostRecentCall = {}; }; @@ -286,13 +294,10 @@ jasmine.createSpy = function(name) { spyObj.wasCalled = true; spyObj.callCount++; var args = jasmine.util.argsToArray(arguments); - //spyObj.mostRecentCall = { - // object: this, - // args: args - //}; spyObj.mostRecentCall.object = this; spyObj.mostRecentCall.args = args; spyObj.argsForCall.push(args); + spyObj.calls.push({object: this, args: args}); return spyObj.plan.apply(this, arguments); };