diff --git a/doc/files.html b/doc/files.html index bf7627d..1284c83 100644 --- a/doc/files.html +++ b/doc/files.html @@ -454,7 +454,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 286c31b..582b23c 100644 --- a/doc/index.html +++ b/doc/index.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 7cc1447..1f30daf 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -912,7 +912,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:21 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:00 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index aa3f4e7..1e39095 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -411,7 +411,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:00 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Clock.html b/doc/symbols/jasmine.Clock.html index 6f8aa91..35f552e 100644 --- a/doc/symbols/jasmine.Clock.html +++ b/doc/symbols/jasmine.Clock.html @@ -672,7 +672,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:00 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 44245e8..de4e958 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -1163,7 +1163,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 5bedb54..b0d0ba5 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -816,7 +816,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index f176252..8a598ee 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -257,7 +257,7 @@ ul.inheritsList  
- jasmine.Matchers(env, actual, spec) + jasmine.Matchers(env, actual, spec, opt_isNot)
@@ -534,7 +534,7 @@ ul.inheritsList
- jasmine.Matchers(env, actual, spec) + jasmine.Matchers(env, actual, spec, opt_isNot)
@@ -567,6 +567,12 @@ ul.inheritsList
+
+ opt_isNot + +
+
+ @@ -767,6 +773,13 @@ ul.inheritsList +
+
Deprecated:
+
+ Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. +
+
+ @@ -1455,7 +1468,7 @@ a pattern or a String.
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 160c5d9..9a45068 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -388,7 +388,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 4599bee..5836f68 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 0c8a42c..9e52925 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -568,7 +568,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index ea05684..2ea1691 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 5fe4f4c..bfbfde1 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -322,7 +322,7 @@ ul.inheritsList   -
after(doAfter, test) +
after(doAfter)
@@ -680,7 +680,7 @@ ul.inheritsList
- after(doAfter, test) + after(doAfter)
@@ -701,12 +701,6 @@ ul.inheritsList
-
- test - -
-
- @@ -1253,7 +1247,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index bd08ca0..38c9024 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -849,7 +849,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index 6ed8176..efb39e3 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -699,7 +699,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 2904d8a..569cafe 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -1339,7 +1339,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:21 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:00 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index f630c16..41a1fb8 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -529,7 +529,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Mar 18 2010 20:35:01 GMT-0700 (PDT)
diff --git a/doc/symbols/src/src_Env.js.html b/doc/symbols/src/src_Env.js.html index 9c858a7..04aa468 100644 --- a/doc/symbols/src/src_Env.js.html +++ b/doc/symbols/src/src_Env.js.html @@ -188,53 +188,61 @@ 181 mismatchKeys = mismatchKeys || []; 182 mismatchValues = mismatchValues || []; 183 -184 if (a === b) return true; -185 -186 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { -187 return (a == jasmine.undefined && b == jasmine.undefined); +184 for (var i = 0; i < this.equalityTesters_.length; i++) { +185 var equalityTester = this.equalityTesters_[i]; +186 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); +187 if (result !== jasmine.undefined) return result; 188 } 189 -190 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -191 return a === b; -192 } -193 -194 if (a instanceof Date && b instanceof Date) { -195 return a.getTime() == b.getTime(); -196 } -197 -198 if (a instanceof jasmine.Matchers.Any) { -199 return a.matches(b); -200 } -201 -202 if (b instanceof jasmine.Matchers.Any) { -203 return b.matches(a); -204 } -205 -206 if (typeof a === "object" && typeof b === "object") { -207 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -208 } -209 -210 for (var i = 0; i < this.equalityTesters_.length; i++) { -211 var equalityTester = this.equalityTesters_[i]; -212 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -213 if (result !== jasmine.undefined) return result; +190 if (a === b) return true; +191 +192 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { +193 return (a == jasmine.undefined && b == jasmine.undefined); +194 } +195 +196 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +197 return a === b; +198 } +199 +200 if (a instanceof Date && b instanceof Date) { +201 return a.getTime() == b.getTime(); +202 } +203 +204 if (a instanceof jasmine.Matchers.Any) { +205 return a.matches(b); +206 } +207 +208 if (b instanceof jasmine.Matchers.Any) { +209 return b.matches(a); +210 } +211 +212 if (jasmine.isString_(a) && jasmine.isString_(b)) { +213 return (a == b); 214 } 215 -216 //Straight check -217 return (a === b); -218 }; +216 if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { +217 return (a == b); +218 } 219 -220 jasmine.Env.prototype.contains_ = function(haystack, needle) { -221 if (jasmine.isArray_(haystack)) { -222 for (var i = 0; i < haystack.length; i++) { -223 if (this.equals_(haystack[i], needle)) return true; -224 } -225 return false; -226 } -227 return haystack.indexOf(needle) >= 0; -228 }; -229 -230 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -231 this.equalityTesters_.push(equalityTester); -232 }; -233 \ No newline at end of file +220 if (typeof a === "object" && typeof b === "object") { +221 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +222 } +223 +224 //Straight check +225 return (a === b); +226 }; +227 +228 jasmine.Env.prototype.contains_ = function(haystack, needle) { +229 if (jasmine.isArray_(haystack)) { +230 for (var i = 0; i < haystack.length; i++) { +231 if (this.equals_(haystack[i], needle)) return true; +232 } +233 return false; +234 } +235 return haystack.indexOf(needle) >= 0; +236 }; +237 +238 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +239 this.equalityTesters_.push(equalityTester); +240 }; +241 \ No newline at end of file diff --git a/doc/symbols/src/src_Matchers.js.html b/doc/symbols/src/src_Matchers.js.html index 20f9391..8814321 100644 --- a/doc/symbols/src/src_Matchers.js.html +++ b/doc/symbols/src/src_Matchers.js.html @@ -11,318 +11,334 @@ 4 * @param actual 5 * @param {jasmine.Spec} spec 6 */ - 7 jasmine.Matchers = function(env, actual, spec) { + 7 jasmine.Matchers = function(env, actual, spec, opt_isNot) { 8 this.env = env; 9 this.actual = actual; 10 this.spec = spec; - 11 this.reportWasCalled_ = false; - 12 }; - 13 - 14 jasmine.Matchers.pp = function(str) { - 15 return jasmine.util.htmlEscape(jasmine.pp(str)); - 16 }; - 17 - 18 /** @deprecated */ - 19 jasmine.Matchers.prototype.report = function(result, failing_message, details) { - 20 // todo first: report deprecation warning [xw] - 21 // todo later: throw new Error("As of jasmine 0.xx, custom matchers must be implemented differently -- please see jasmine docs"); - 22 this.reportWasCalled_ = true; - 23 var expectationResult = new jasmine.ExpectationResult({ - 24 passed: result, - 25 message: failing_message, - 26 details: details - 27 }); - 28 this.spec.addMatcherResult(expectationResult); - 29 return result; - 30 }; - 31 - 32 jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { - 33 for (var methodName in prototype) { - 34 if (methodName == 'report') continue; - 35 var orig = prototype[methodName]; - 36 matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); - 37 } - 38 }; - 39 - 40 jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { - 41 return function() { - 42 var matcherArgs = jasmine.util.argsToArray(arguments); - 43 var result = matcherFunction.apply(this, arguments); - 44 if (this.reportWasCalled_) return result; - 45 - 46 var message; - 47 if (!result) { - 48 if (this.message) { - 49 message = this.message.apply(this, arguments); - 50 } else { - 51 var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); - 52 message = "Expected " + jasmine.pp(this.actual) + " " + englishyPredicate; - 53 if (matcherArgs.length > 0) { - 54 for (var i = 0; i < matcherArgs.length; i++) { - 55 if (i > 0) message += ","; - 56 message += " " + jasmine.pp(matcherArgs[i]); - 57 } - 58 } - 59 message += "."; - 60 } - 61 } - 62 var expectationResult = new jasmine.ExpectationResult({ - 63 matcherName: matcherName, - 64 passed: result, - 65 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], - 66 actual: this.actual, - 67 message: message - 68 }); - 69 this.spec.addMatcherResult(expectationResult); - 70 return result; - 71 }; - 72 }; - 73 - 74 - 75 - 76 - 77 /** - 78 * toBe: compares the actual to the expected using === - 79 * @param expected - 80 */ - 81 jasmine.Matchers.prototype.toBe = function(expected) { - 82 return this.actual === expected; - 83 }; - 84 - 85 /** - 86 * toNotBe: compares the actual to the expected using !== - 87 * @param expected - 88 */ - 89 jasmine.Matchers.prototype.toNotBe = function(expected) { - 90 return this.actual !== expected; - 91 }; - 92 - 93 /** - 94 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. - 95 * - 96 * @param expected - 97 */ - 98 jasmine.Matchers.prototype.toEqual = function(expected) { - 99 return this.env.equals_(this.actual, expected); -100 }; -101 -102 /** -103 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual -104 * @param expected -105 */ -106 jasmine.Matchers.prototype.toNotEqual = function(expected) { -107 return !this.env.equals_(this.actual, expected); -108 }; -109 -110 /** -111 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -112 * a pattern or a String. -113 * -114 * @param expected -115 */ -116 jasmine.Matchers.prototype.toMatch = function(expected) { -117 return new RegExp(expected).test(this.actual); -118 }; -119 -120 /** -121 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -122 * @param expected -123 */ -124 jasmine.Matchers.prototype.toNotMatch = function(expected) { -125 return !(new RegExp(expected).test(this.actual)); -126 }; -127 -128 /** -129 * Matcher that compares the actual to jasmine.undefined. + 11 this.isNot = opt_isNot || false; + 12 this.reportWasCalled_ = false; + 13 }; + 14 + 15 // todo: @deprecated as of Jasmine 0.11, remove soon [xw] + 16 jasmine.Matchers.pp = function(str) { + 17 throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!"); + 18 this.report(); + 19 }; + 20 + 21 /** @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. */ + 22 jasmine.Matchers.prototype.report = function(result, failing_message, details) { + 23 // todo: report a deprecation warning [xw] + 24 + 25 if (this.isNot) { + 26 throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs"); + 27 } + 28 + 29 this.reportWasCalled_ = true; + 30 var expectationResult = new jasmine.ExpectationResult({ + 31 passed: result, + 32 message: failing_message, + 33 details: details + 34 }); + 35 this.spec.addMatcherResult(expectationResult); + 36 return result; + 37 }; + 38 + 39 jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { + 40 for (var methodName in prototype) { + 41 if (methodName == 'report') continue; + 42 var orig = prototype[methodName]; + 43 matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); + 44 } + 45 }; + 46 + 47 jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { + 48 return function() { + 49 var matcherArgs = jasmine.util.argsToArray(arguments); + 50 var result = matcherFunction.apply(this, arguments); + 51 + 52 if (this.isNot) { + 53 result = !result; + 54 } + 55 + 56 if (this.reportWasCalled_) return result; + 57 + 58 var message; + 59 if (!result) { + 60 if (this.message) { + 61 message = this.message.apply(this, arguments); + 62 if (jasmine.isArray_(message)) { + 63 message = message[this.isNot ? 1 : 0]; + 64 } + 65 } else { + 66 var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); + 67 message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate; + 68 if (matcherArgs.length > 0) { + 69 for (var i = 0; i < matcherArgs.length; i++) { + 70 if (i > 0) message += ","; + 71 message += " " + jasmine.pp(matcherArgs[i]); + 72 } + 73 } + 74 message += "."; + 75 } + 76 } + 77 var expectationResult = new jasmine.ExpectationResult({ + 78 matcherName: matcherName, + 79 passed: result, + 80 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], + 81 actual: this.actual, + 82 message: message + 83 }); + 84 this.spec.addMatcherResult(expectationResult); + 85 return result; + 86 }; + 87 }; + 88 + 89 + 90 + 91 + 92 /** + 93 * toBe: compares the actual to the expected using === + 94 * @param expected + 95 */ + 96 jasmine.Matchers.prototype.toBe = function(expected) { + 97 return this.actual === expected; + 98 }; + 99 +100 /** +101 * toNotBe: compares the actual to the expected using !== +102 * @param expected +103 */ +104 jasmine.Matchers.prototype.toNotBe = function(expected) { +105 return this.actual !== expected; +106 }; +107 +108 /** +109 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. +110 * +111 * @param expected +112 */ +113 jasmine.Matchers.prototype.toEqual = function(expected) { +114 return this.env.equals_(this.actual, expected); +115 }; +116 +117 /** +118 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual +119 * @param expected +120 */ +121 jasmine.Matchers.prototype.toNotEqual = function(expected) { +122 return !this.env.equals_(this.actual, expected); +123 }; +124 +125 /** +126 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +127 * a pattern or a String. +128 * +129 * @param expected 130 */ -131 jasmine.Matchers.prototype.toBeDefined = function() { -132 return (this.actual !== jasmine.undefined); +131 jasmine.Matchers.prototype.toMatch = function(expected) { +132 return new RegExp(expected).test(this.actual); 133 }; 134 135 /** -136 * Matcher that compares the actual to jasmine.undefined. -137 */ -138 jasmine.Matchers.prototype.toBeUndefined = function() { -139 return (this.actual === jasmine.undefined); -140 }; -141 -142 /** -143 * Matcher that compares the actual to null. -144 */ -145 jasmine.Matchers.prototype.toBeNull = function() { -146 return (this.actual === null); -147 }; -148 -149 /** -150 * Matcher that boolean not-nots the actual. -151 */ -152 jasmine.Matchers.prototype.toBeTruthy = function() { -153 return !!this.actual; -154 }; -155 +136 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +137 * @param expected +138 */ +139 jasmine.Matchers.prototype.toNotMatch = function(expected) { +140 return !(new RegExp(expected).test(this.actual)); +141 }; +142 +143 /** +144 * Matcher that compares the actual to jasmine.undefined. +145 */ +146 jasmine.Matchers.prototype.toBeDefined = function() { +147 return (this.actual !== jasmine.undefined); +148 }; +149 +150 /** +151 * Matcher that compares the actual to jasmine.undefined. +152 */ +153 jasmine.Matchers.prototype.toBeUndefined = function() { +154 return (this.actual === jasmine.undefined); +155 }; 156 157 /** -158 * Matcher that boolean nots the actual. +158 * Matcher that compares the actual to null. 159 */ -160 jasmine.Matchers.prototype.toBeFalsy = function() { -161 return !this.actual; +160 jasmine.Matchers.prototype.toBeNull = function() { +161 return (this.actual === null); 162 }; 163 164 /** -165 * Matcher that checks to see if the actual, a Jasmine spy, was called. +165 * Matcher that boolean not-nots the actual. 166 */ -167 jasmine.Matchers.prototype.wasCalled = function() { -168 if (arguments.length > 0) { -169 throw new Error('wasCalled does not take arguments, use wasCalledWith'); -170 } +167 jasmine.Matchers.prototype.toBeTruthy = function() { +168 return !!this.actual; +169 }; +170 171 -172 if (!jasmine.isSpy(this.actual)) { -173 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -174 } -175 -176 this.message = function() { -177 return "Expected spy " + this.actual.identity + " to have been called."; -178 }; -179 -180 return this.actual.wasCalled; -181 }; -182 -183 /** -184 * Matcher that checks to see if the actual, a Jasmine spy, was not called. -185 */ -186 jasmine.Matchers.prototype.wasNotCalled = function() { -187 if (arguments.length > 0) { -188 throw new Error('wasNotCalled does not take arguments'); +172 /** +173 * Matcher that boolean nots the actual. +174 */ +175 jasmine.Matchers.prototype.toBeFalsy = function() { +176 return !this.actual; +177 }; +178 +179 /** +180 * Matcher that checks to see if the actual, a Jasmine spy, was called. +181 */ +182 jasmine.Matchers.prototype.wasCalled = function() { +183 if (arguments.length > 0) { +184 throw new Error('wasCalled does not take arguments, use wasCalledWith'); +185 } +186 +187 if (!jasmine.isSpy(this.actual)) { +188 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); 189 } 190 -191 if (!jasmine.isSpy(this.actual)) { -192 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -193 } +191 this.message = function() { +192 return "Expected spy " + this.actual.identity + " to have been called."; +193 }; 194 -195 this.message = function() { -196 return "Expected spy " + this.actual.identity + " to not have been called."; -197 }; -198 -199 return !this.actual.wasCalled; -200 }; -201 -202 /** -203 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. -204 * -205 * @example -206 * -207 */ -208 jasmine.Matchers.prototype.wasCalledWith = function() { -209 if (!jasmine.isSpy(this.actual)) { -210 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -211 } -212 -213 this.message = function() { -214 if (this.actual.callCount == 0) { -215 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; -216 } else { -217 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); -218 } -219 }; -220 -221 return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); -222 }; -223 -224 jasmine.Matchers.prototype.wasNotCalledWith = function() { +195 return this.actual.wasCalled; +196 }; +197 +198 /** +199 * Matcher that checks to see if the actual, a Jasmine spy, was not called. +200 */ +201 jasmine.Matchers.prototype.wasNotCalled = function() { +202 if (arguments.length > 0) { +203 throw new Error('wasNotCalled does not take arguments'); +204 } +205 +206 if (!jasmine.isSpy(this.actual)) { +207 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +208 } +209 +210 this.message = function() { +211 return "Expected spy " + this.actual.identity + " to not have been called."; +212 }; +213 +214 return !this.actual.wasCalled; +215 }; +216 +217 /** +218 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. +219 * +220 * @example +221 * +222 */ +223 jasmine.Matchers.prototype.wasCalledWith = function() { +224 var expectedArgs = jasmine.util.argsToArray(arguments); 225 if (!jasmine.isSpy(this.actual)) { -226 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +226 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); 227 } -228 -229 this.message = function() { -230 return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; -231 }; -232 -233 return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); -234 }; +228 this.message = function() { +229 if (this.actual.callCount == 0) { +230 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; +231 } else { +232 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); +233 } +234 }; 235 -236 /** -237 * Matcher that checks that the expected item is an element in the actual Array. -238 * -239 * @param {Object} expected -240 */ -241 jasmine.Matchers.prototype.toContain = function(expected) { -242 return this.env.contains_(this.actual, expected); -243 }; +236 return this.env.contains_(this.actual.argsForCall, expectedArgs); +237 }; +238 +239 jasmine.Matchers.prototype.wasNotCalledWith = function() { +240 var expectedArgs = jasmine.util.argsToArray(arguments); +241 if (!jasmine.isSpy(this.actual)) { +242 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +243 } 244 -245 /** -246 * Matcher that checks that the expected item is NOT an element in the actual Array. -247 * -248 * @param {Object} expected -249 */ -250 jasmine.Matchers.prototype.toNotContain = function(expected) { -251 return !this.env.contains_(this.actual, expected); -252 }; -253 -254 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -255 return this.actual < expected; -256 }; -257 -258 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -259 return this.actual > expected; -260 }; -261 -262 /** -263 * Matcher that checks that the expected exception was thrown by the actual. -264 * -265 * @param {String} expected -266 */ -267 jasmine.Matchers.prototype.toThrow = function(expected) { -268 var result = false; -269 var exception; -270 if (typeof this.actual != 'function') { -271 throw new Error('Actual is not a function'); -272 } -273 try { -274 this.actual(); -275 } catch (e) { -276 exception = e; -277 } -278 if (exception) { -279 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); -280 } -281 -282 this.message = function() { -283 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -284 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); -285 } else { -286 return "Expected function to throw an exception."; -287 } -288 }; -289 -290 return result; -291 }; -292 -293 jasmine.Matchers.Any = function(expectedClass) { -294 this.expectedClass = expectedClass; -295 }; -296 -297 jasmine.Matchers.Any.prototype.matches = function(other) { -298 if (this.expectedClass == String) { -299 return typeof other == 'string' || other instanceof String; -300 } -301 -302 if (this.expectedClass == Number) { -303 return typeof other == 'number' || other instanceof Number; -304 } +245 this.message = function() { +246 return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; +247 }; +248 +249 return !this.env.contains_(this.actual.argsForCall, expectedArgs); +250 }; +251 +252 /** +253 * Matcher that checks that the expected item is an element in the actual Array. +254 * +255 * @param {Object} expected +256 */ +257 jasmine.Matchers.prototype.toContain = function(expected) { +258 return this.env.contains_(this.actual, expected); +259 }; +260 +261 /** +262 * Matcher that checks that the expected item is NOT an element in the actual Array. +263 * +264 * @param {Object} expected +265 */ +266 jasmine.Matchers.prototype.toNotContain = function(expected) { +267 return !this.env.contains_(this.actual, expected); +268 }; +269 +270 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +271 return this.actual < expected; +272 }; +273 +274 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +275 return this.actual > expected; +276 }; +277 +278 /** +279 * Matcher that checks that the expected exception was thrown by the actual. +280 * +281 * @param {String} expected +282 */ +283 jasmine.Matchers.prototype.toThrow = function(expected) { +284 var result = false; +285 var exception; +286 if (typeof this.actual != 'function') { +287 throw new Error('Actual is not a function'); +288 } +289 try { +290 this.actual(); +291 } catch (e) { +292 exception = e; +293 } +294 if (exception) { +295 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +296 } +297 +298 this.message = function() { +299 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { +300 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); +301 } else { +302 return "Expected function to throw an exception."; +303 } +304 }; 305 -306 if (this.expectedClass == Function) { -307 return typeof other == 'function' || other instanceof Function; -308 } -309 -310 if (this.expectedClass == Object) { -311 return typeof other == 'object'; -312 } -313 -314 return other instanceof this.expectedClass; -315 }; -316 -317 jasmine.Matchers.Any.prototype.toString = function() { -318 return '<jasmine.any(' + this.expectedClass + ')>'; -319 }; -320 -321 \ No newline at end of file +306 return result; +307 }; +308 +309 jasmine.Matchers.Any = function(expectedClass) { +310 this.expectedClass = expectedClass; +311 }; +312 +313 jasmine.Matchers.Any.prototype.matches = function(other) { +314 if (this.expectedClass == String) { +315 return typeof other == 'string' || other instanceof String; +316 } +317 +318 if (this.expectedClass == Number) { +319 return typeof other == 'number' || other instanceof Number; +320 } +321 +322 if (this.expectedClass == Function) { +323 return typeof other == 'function' || other instanceof Function; +324 } +325 +326 if (this.expectedClass == Object) { +327 return typeof other == 'object'; +328 } +329 +330 return other instanceof this.expectedClass; +331 }; +332 +333 jasmine.Matchers.Any.prototype.toString = function() { +334 return '<jasmine.any(' + this.expectedClass + ')>'; +335 }; +336 +337 \ No newline at end of file diff --git a/doc/symbols/src/src_Spec.js.html b/doc/symbols/src/src_Spec.js.html index 8b69c25..4743b11 100644 --- a/doc/symbols/src/src_Spec.js.html +++ b/doc/symbols/src/src_Spec.js.html @@ -72,140 +72,143 @@ 65 }; 66 67 jasmine.Spec.prototype.expect = function(actual) { - 68 return new (this.getMatchersClass_())(this.env, actual, this); - 69 }; - 70 - 71 jasmine.Spec.prototype.waits = function(timeout) { - 72 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); - 73 this.addToQueue(waitsFunc); - 74 return this; - 75 }; - 76 - 77 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { - 78 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); - 79 this.addToQueue(waitsForFunc); - 80 return this; - 81 }; - 82 - 83 jasmine.Spec.prototype.fail = function (e) { - 84 var expectationResult = new jasmine.ExpectationResult({ - 85 passed: false, - 86 message: e ? jasmine.util.formatException(e) : 'Exception' - 87 }); - 88 this.results_.addResult(expectationResult); - 89 }; - 90 - 91 jasmine.Spec.prototype.getMatchersClass_ = function() { - 92 return this.matchersClass || this.env.matchersClass; - 93 }; - 94 - 95 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { - 96 var parent = this.getMatchersClass_(); - 97 var newMatchersClass = function() { - 98 parent.apply(this, arguments); - 99 }; -100 jasmine.util.inherit(newMatchersClass, parent); -101 jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); -102 this.matchersClass = newMatchersClass; -103 }; -104 -105 jasmine.Spec.prototype.finishCallback = function() { -106 this.env.reporter.reportSpecResults(this); -107 }; -108 -109 jasmine.Spec.prototype.finish = function(onComplete) { -110 this.removeAllSpies(); -111 this.finishCallback(); -112 if (onComplete) { -113 onComplete(); -114 } -115 }; -116 -117 jasmine.Spec.prototype.after = function(doAfter, test) { + 68 var positive = new (this.getMatchersClass_())(this.env, actual, this); + 69 positive.not = new (this.getMatchersClass_())(this.env, actual, this, true); + 70 return positive; + 71 }; + 72 + 73 jasmine.Spec.prototype.waits = function(timeout) { + 74 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); + 75 this.addToQueue(waitsFunc); + 76 return this; + 77 }; + 78 + 79 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { + 80 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); + 81 this.addToQueue(waitsForFunc); + 82 return this; + 83 }; + 84 + 85 jasmine.Spec.prototype.fail = function (e) { + 86 var expectationResult = new jasmine.ExpectationResult({ + 87 passed: false, + 88 message: e ? jasmine.util.formatException(e) : 'Exception' + 89 }); + 90 this.results_.addResult(expectationResult); + 91 }; + 92 + 93 jasmine.Spec.prototype.getMatchersClass_ = function() { + 94 return this.matchersClass || this.env.matchersClass; + 95 }; + 96 + 97 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { + 98 var parent = this.getMatchersClass_(); + 99 var newMatchersClass = function() { +100 parent.apply(this, arguments); +101 }; +102 jasmine.util.inherit(newMatchersClass, parent); +103 jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); +104 this.matchersClass = newMatchersClass; +105 }; +106 +107 jasmine.Spec.prototype.finishCallback = function() { +108 this.env.reporter.reportSpecResults(this); +109 }; +110 +111 jasmine.Spec.prototype.finish = function(onComplete) { +112 this.removeAllSpies(); +113 this.finishCallback(); +114 if (onComplete) { +115 onComplete(); +116 } +117 }; 118 -119 if (this.queue.isRunning()) { -120 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -121 } else { -122 this.afterCallbacks.unshift(doAfter); -123 } -124 }; -125 -126 jasmine.Spec.prototype.execute = function(onComplete) { -127 var spec = this; -128 if (!spec.env.specFilter(spec)) { -129 spec.results_.skipped = true; -130 spec.finish(onComplete); -131 return; -132 } -133 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); -134 -135 spec.env.currentSpec = spec; -136 -137 spec.addBeforesAndAftersToQueue(); -138 -139 spec.queue.start(function () { -140 spec.finish(onComplete); -141 }); -142 }; -143 -144 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -145 var runner = this.env.currentRunner(); -146 for (var suite = this.suite; suite; suite = suite.parentSuite) { -147 for (var i = 0; i < suite.before_.length; i++) { -148 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -149 } -150 } -151 for (var i = 0; i < runner.before_.length; i++) { -152 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +119 jasmine.Spec.prototype.after = function(doAfter) { +120 if (this.queue.isRunning()) { +121 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +122 } else { +123 this.afterCallbacks.unshift(doAfter); +124 } +125 }; +126 +127 jasmine.Spec.prototype.execute = function(onComplete) { +128 var spec = this; +129 if (!spec.env.specFilter(spec)) { +130 spec.results_.skipped = true; +131 spec.finish(onComplete); +132 return; +133 } +134 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +135 +136 spec.env.currentSpec = spec; +137 +138 spec.addBeforesAndAftersToQueue(); +139 +140 spec.queue.start(function () { +141 spec.finish(onComplete); +142 }); +143 }; +144 +145 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +146 var runner = this.env.currentRunner(); +147 var i; +148 +149 for (var suite = this.suite; suite; suite = suite.parentSuite) { +150 for (i = 0; i < suite.before_.length; i++) { +151 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +152 } 153 } -154 for (i = 0; i < this.afterCallbacks.length; i++) { -155 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +154 for (i = 0; i < runner.before_.length; i++) { +155 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); 156 } -157 for (suite = this.suite; suite; suite = suite.parentSuite) { -158 for (var i = 0; i < suite.after_.length; i++) { -159 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -160 } -161 } -162 for (var i = 0; i < runner.after_.length; i++) { -163 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +157 for (i = 0; i < this.afterCallbacks.length; i++) { +158 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +159 } +160 for (suite = this.suite; suite; suite = suite.parentSuite) { +161 for (i = 0; i < suite.after_.length; i++) { +162 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +163 } 164 } -165 }; -166 -167 jasmine.Spec.prototype.explodes = function() { -168 throw 'explodes function should not have been called'; -169 }; -170 -171 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -172 if (obj == jasmine.undefined) { -173 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -174 } -175 -176 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { -177 throw methodName + '() method does not exist'; -178 } -179 -180 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -181 throw new Error(methodName + ' has already been spied upon'); -182 } -183 -184 var spyObj = jasmine.createSpy(methodName); -185 -186 this.spies_.push(spyObj); -187 spyObj.baseObj = obj; -188 spyObj.methodName = methodName; -189 spyObj.originalValue = obj[methodName]; -190 -191 obj[methodName] = spyObj; -192 -193 return spyObj; -194 }; +165 for (i = 0; i < runner.after_.length; i++) { +166 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +167 } +168 }; +169 +170 jasmine.Spec.prototype.explodes = function() { +171 throw 'explodes function should not have been called'; +172 }; +173 +174 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +175 if (obj == jasmine.undefined) { +176 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +177 } +178 +179 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { +180 throw methodName + '() method does not exist'; +181 } +182 +183 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +184 throw new Error(methodName + ' has already been spied upon'); +185 } +186 +187 var spyObj = jasmine.createSpy(methodName); +188 +189 this.spies_.push(spyObj); +190 spyObj.baseObj = obj; +191 spyObj.methodName = methodName; +192 spyObj.originalValue = obj[methodName]; +193 +194 obj[methodName] = spyObj; 195 -196 jasmine.Spec.prototype.removeAllSpies = function() { -197 for (var i = 0; i < this.spies_.length; i++) { -198 var spy = this.spies_[i]; -199 spy.baseObj[spy.methodName] = spy.originalValue; -200 } -201 this.spies_ = []; -202 }; -203 -204 \ No newline at end of file +196 return spyObj; +197 }; +198 +199 jasmine.Spec.prototype.removeAllSpies = function() { +200 for (var i = 0; i < this.spies_.length; i++) { +201 var spy = this.spies_[i]; +202 spy.baseObj[spy.methodName] = spy.originalValue; +203 } +204 this.spies_ = []; +205 }; +206 +207 \ No newline at end of file diff --git a/doc/symbols/src/src_base.js.html b/doc/symbols/src/src_base.js.html index 388f185..a917d73 100644 --- a/doc/symbols/src/src_base.js.html +++ b/doc/symbols/src/src_base.js.html @@ -22,7 +22,7 @@ 15 /** 16 * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code is just 17 * a plain old variable and may be redefined by somebody else. - 18 * + 18 * 19 * @private 20 */ 21 jasmine.undefined = jasmine.___undefined___; @@ -73,8 +73,8 @@ 66 67 /** @deprecated */ 68 this.details = params.details; - 69 - 70 this.message = this.passed_ ? 'Passed.' : params.message; + 69 + 70 this.message = this.passed_ ? 'Passed.' : params.message; 71 this.trace = this.passed_ ? '' : new Error(this.message); 72 }; 73 @@ -96,460 +96,490 @@ 89 * @returns {Boolean} 90 */ 91 jasmine.isArray_ = function(value) { - 92 return value && - 93 typeof value === 'object' && - 94 typeof value.length === 'number' && - 95 typeof value.splice === 'function' && - 96 !(value.propertyIsEnumerable('length')); - 97 }; - 98 - 99 /** -100 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. -101 * -102 * @param value {Object} an object to be outputted -103 * @returns {String} -104 */ -105 jasmine.pp = function(value) { -106 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); -107 stringPrettyPrinter.format(value); -108 return stringPrettyPrinter.string; -109 }; -110 -111 /** -112 * Returns true if the object is a DOM Node. -113 * -114 * @param {Object} obj object to check -115 * @returns {Boolean} -116 */ -117 jasmine.isDomNode = function(obj) { -118 return obj['nodeType'] > 0; -119 }; -120 -121 /** -122 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. -123 * -124 * @example -125 * // don't care about which function is passed in, as long as it's a function -126 * expect(mySpy).wasCalledWith(jasmine.any(Function)); -127 * -128 * @param {Class} clazz -129 * @returns matchable object of the type clazz -130 */ -131 jasmine.any = function(clazz) { -132 return new jasmine.Matchers.Any(clazz); -133 }; -134 -135 /** -136 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. -137 * -138 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine -139 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. + 92 return jasmine.isA_("Array", value); + 93 }; + 94 + 95 /** + 96 * @ignore + 97 * @private + 98 * @param value + 99 * @returns {Boolean} +100 */ +101 jasmine.isString_ = function(value) { +102 return jasmine.isA_("String", value); +103 }; +104 +105 /** +106 * @ignore +107 * @private +108 * @param value +109 * @returns {Boolean} +110 */ +111 jasmine.isNumber_ = function(value) { +112 return jasmine.isA_("Number", value); +113 }; +114 +115 /** +116 * @ignore +117 * @private +118 * @param {String} typeName +119 * @param value +120 * @returns {Boolean} +121 */ +122 jasmine.isA_ = function(typeName, value) { +123 return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; +124 }; +125 +126 /** +127 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. +128 * +129 * @param value {Object} an object to be outputted +130 * @returns {String} +131 */ +132 jasmine.pp = function(value) { +133 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); +134 stringPrettyPrinter.format(value); +135 return stringPrettyPrinter.string; +136 }; +137 +138 /** +139 * Returns true if the object is a DOM Node. 140 * -141 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) -142 * Spies are torn down at the end of every spec. -143 * -144 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. -145 * -146 * @example -147 * // a stub -148 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere -149 * -150 * // spy example -151 * var foo = { -152 * not: function(bool) { return !bool; } -153 * } +141 * @param {Object} obj object to check +142 * @returns {Boolean} +143 */ +144 jasmine.isDomNode = function(obj) { +145 return obj['nodeType'] > 0; +146 }; +147 +148 /** +149 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. +150 * +151 * @example +152 * // don't care about which function is passed in, as long as it's a function +153 * expect(mySpy).wasCalledWith(jasmine.any(Function)); 154 * -155 * // actual foo.not will not be called, execution stops -156 * spyOn(foo, 'not'); -157 -158 // foo.not spied upon, execution will continue to implementation -159 * spyOn(foo, 'not').andCallThrough(); -160 * -161 * // fake example -162 * var foo = { -163 * not: function(bool) { return !bool; } -164 * } -165 * -166 * // foo.not(val) will return val -167 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); -168 * -169 * // mock example -170 * foo.not(7 == 7); -171 * expect(foo.not).wasCalled(); -172 * expect(foo.not).wasCalledWith(true); -173 * -174 * @constructor -175 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj -176 * @param {String} name -177 */ -178 jasmine.Spy = function(name) { -179 /** -180 * The name of the spy, if provided. -181 */ -182 this.identity = name || 'unknown'; -183 /** -184 * Is this Object a spy? -185 */ -186 this.isSpy = true; -187 /** -188 * The actual function this spy stubs. -189 */ -190 this.plan = function() { -191 }; -192 /** -193 * Tracking of the most recent call to the spy. -194 * @example -195 * var mySpy = jasmine.createSpy('foo'); -196 * mySpy(1, 2); -197 * mySpy.mostRecentCall.args = [1, 2]; -198 */ -199 this.mostRecentCall = {}; -200 -201 /** -202 * Holds arguments for each call to the spy, indexed by call count -203 * @example -204 * var mySpy = jasmine.createSpy('foo'); -205 * mySpy(1, 2); -206 * mySpy(7, 8); -207 * mySpy.mostRecentCall.args = [7, 8]; -208 * mySpy.argsForCall[0] = [1, 2]; -209 * mySpy.argsForCall[1] = [7, 8]; -210 */ -211 this.argsForCall = []; -212 this.calls = []; -213 }; -214 -215 /** -216 * Tells a spy to call through to the actual implemenatation. -217 * -218 * @example -219 * var foo = { -220 * bar: function() { // do some stuff } -221 * } -222 * -223 * // defining a spy on an existing property: foo.bar -224 * spyOn(foo, 'bar').andCallThrough(); -225 */ -226 jasmine.Spy.prototype.andCallThrough = function() { -227 this.plan = this.originalValue; -228 return this; -229 }; -230 -231 /** -232 * For setting the return value of a spy. -233 * -234 * @example -235 * // defining a spy from scratch: foo() returns 'baz' -236 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); -237 * -238 * // defining a spy on an existing property: foo.bar() returns 'baz' -239 * spyOn(foo, 'bar').andReturn('baz'); -240 * -241 * @param {Object} value -242 */ -243 jasmine.Spy.prototype.andReturn = function(value) { -244 this.plan = function() { -245 return value; -246 }; -247 return this; -248 }; -249 -250 /** -251 * For throwing an exception when a spy is called. -252 * -253 * @example -254 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' -255 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); -256 * -257 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' -258 * spyOn(foo, 'bar').andThrow('baz'); -259 * -260 * @param {String} exceptionMsg -261 */ -262 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { -263 this.plan = function() { -264 throw exceptionMsg; -265 }; -266 return this; -267 }; -268 -269 /** -270 * Calls an alternate implementation when a spy is called. -271 * -272 * @example -273 * var baz = function() { -274 * // do some stuff, return something -275 * } -276 * // defining a spy from scratch: foo() calls the function baz -277 * var foo = jasmine.createSpy('spy on foo').andCall(baz); -278 * -279 * // defining a spy on an existing property: foo.bar() calls an anonymnous function -280 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); -281 * -282 * @param {Function} fakeFunc -283 */ -284 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { -285 this.plan = fakeFunc; -286 return this; -287 }; -288 -289 /** -290 * Resets all of a spy's the tracking variables so that it can be used again. -291 * -292 * @example -293 * spyOn(foo, 'bar'); -294 * -295 * foo.bar(); -296 * -297 * expect(foo.bar.callCount).toEqual(1); +155 * @param {Class} clazz +156 * @returns matchable object of the type clazz +157 */ +158 jasmine.any = function(clazz) { +159 return new jasmine.Matchers.Any(clazz); +160 }; +161 +162 /** +163 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. +164 * +165 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine +166 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. +167 * +168 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) +169 * Spies are torn down at the end of every spec. +170 * +171 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. +172 * +173 * @example +174 * // a stub +175 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere +176 * +177 * // spy example +178 * var foo = { +179 * not: function(bool) { return !bool; } +180 * } +181 * +182 * // actual foo.not will not be called, execution stops +183 * spyOn(foo, 'not'); +184 +185 // foo.not spied upon, execution will continue to implementation +186 * spyOn(foo, 'not').andCallThrough(); +187 * +188 * // fake example +189 * var foo = { +190 * not: function(bool) { return !bool; } +191 * } +192 * +193 * // foo.not(val) will return val +194 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); +195 * +196 * // mock example +197 * foo.not(7 == 7); +198 * expect(foo.not).wasCalled(); +199 * expect(foo.not).wasCalledWith(true); +200 * +201 * @constructor +202 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj +203 * @param {String} name +204 */ +205 jasmine.Spy = function(name) { +206 /** +207 * The name of the spy, if provided. +208 */ +209 this.identity = name || 'unknown'; +210 /** +211 * Is this Object a spy? +212 */ +213 this.isSpy = true; +214 /** +215 * The actual function this spy stubs. +216 */ +217 this.plan = function() { +218 }; +219 /** +220 * Tracking of the most recent call to the spy. +221 * @example +222 * var mySpy = jasmine.createSpy('foo'); +223 * mySpy(1, 2); +224 * mySpy.mostRecentCall.args = [1, 2]; +225 */ +226 this.mostRecentCall = {}; +227 +228 /** +229 * Holds arguments for each call to the spy, indexed by call count +230 * @example +231 * var mySpy = jasmine.createSpy('foo'); +232 * mySpy(1, 2); +233 * mySpy(7, 8); +234 * mySpy.mostRecentCall.args = [7, 8]; +235 * mySpy.argsForCall[0] = [1, 2]; +236 * mySpy.argsForCall[1] = [7, 8]; +237 */ +238 this.argsForCall = []; +239 this.calls = []; +240 }; +241 +242 /** +243 * Tells a spy to call through to the actual implemenatation. +244 * +245 * @example +246 * var foo = { +247 * bar: function() { // do some stuff } +248 * } +249 * +250 * // defining a spy on an existing property: foo.bar +251 * spyOn(foo, 'bar').andCallThrough(); +252 */ +253 jasmine.Spy.prototype.andCallThrough = function() { +254 this.plan = this.originalValue; +255 return this; +256 }; +257 +258 /** +259 * For setting the return value of a spy. +260 * +261 * @example +262 * // defining a spy from scratch: foo() returns 'baz' +263 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); +264 * +265 * // defining a spy on an existing property: foo.bar() returns 'baz' +266 * spyOn(foo, 'bar').andReturn('baz'); +267 * +268 * @param {Object} value +269 */ +270 jasmine.Spy.prototype.andReturn = function(value) { +271 this.plan = function() { +272 return value; +273 }; +274 return this; +275 }; +276 +277 /** +278 * For throwing an exception when a spy is called. +279 * +280 * @example +281 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' +282 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); +283 * +284 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' +285 * spyOn(foo, 'bar').andThrow('baz'); +286 * +287 * @param {String} exceptionMsg +288 */ +289 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { +290 this.plan = function() { +291 throw exceptionMsg; +292 }; +293 return this; +294 }; +295 +296 /** +297 * Calls an alternate implementation when a spy is called. 298 * -299 * foo.bar.reset(); -300 * -301 * expect(foo.bar.callCount).toEqual(0); -302 */ -303 jasmine.Spy.prototype.reset = function() { -304 this.wasCalled = false; -305 this.callCount = 0; -306 this.argsForCall = []; -307 this.calls = []; -308 this.mostRecentCall = {}; -309 }; -310 -311 jasmine.createSpy = function(name) { -312 -313 var spyObj = function() { -314 spyObj.wasCalled = true; -315 spyObj.callCount++; -316 var args = jasmine.util.argsToArray(arguments); -317 spyObj.mostRecentCall.object = this; -318 spyObj.mostRecentCall.args = args; -319 spyObj.argsForCall.push(args); -320 spyObj.calls.push({object: this, args: args}); -321 return spyObj.plan.apply(this, arguments); -322 }; -323 -324 var spy = new jasmine.Spy(name); -325 -326 for (var prop in spy) { -327 spyObj[prop] = spy[prop]; -328 } -329 -330 spyObj.reset(); -331 -332 return spyObj; -333 }; -334 -335 /** -336 * Determines whether an object is a spy. -337 * -338 * @param {jasmine.Spy|Object} putativeSpy -339 * @returns {Boolean} -340 */ -341 jasmine.isSpy = function(putativeSpy) { -342 return putativeSpy && putativeSpy.isSpy; -343 }; -344 -345 /** -346 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something -347 * large in one call. -348 * -349 * @param {String} baseName name of spy class -350 * @param {Array} methodNames array of names of methods to make spies -351 */ -352 jasmine.createSpyObj = function(baseName, methodNames) { -353 var obj = {}; -354 for (var i = 0; i < methodNames.length; i++) { -355 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); -356 } -357 return obj; -358 }; -359 -360 jasmine.log = function(message) { -361 jasmine.getEnv().currentSpec.log(message); -362 }; -363 -364 /** -365 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. -366 * -367 * @example -368 * // spy example -369 * var foo = { -370 * not: function(bool) { return !bool; } -371 * } -372 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops -373 * -374 * @see jasmine.createSpy -375 * @param obj -376 * @param methodName -377 * @returns a Jasmine spy that can be chained with all spy methods +299 * @example +300 * var baz = function() { +301 * // do some stuff, return something +302 * } +303 * // defining a spy from scratch: foo() calls the function baz +304 * var foo = jasmine.createSpy('spy on foo').andCall(baz); +305 * +306 * // defining a spy on an existing property: foo.bar() calls an anonymnous function +307 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); +308 * +309 * @param {Function} fakeFunc +310 */ +311 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { +312 this.plan = fakeFunc; +313 return this; +314 }; +315 +316 /** +317 * Resets all of a spy's the tracking variables so that it can be used again. +318 * +319 * @example +320 * spyOn(foo, 'bar'); +321 * +322 * foo.bar(); +323 * +324 * expect(foo.bar.callCount).toEqual(1); +325 * +326 * foo.bar.reset(); +327 * +328 * expect(foo.bar.callCount).toEqual(0); +329 */ +330 jasmine.Spy.prototype.reset = function() { +331 this.wasCalled = false; +332 this.callCount = 0; +333 this.argsForCall = []; +334 this.calls = []; +335 this.mostRecentCall = {}; +336 }; +337 +338 jasmine.createSpy = function(name) { +339 +340 var spyObj = function() { +341 spyObj.wasCalled = true; +342 spyObj.callCount++; +343 var args = jasmine.util.argsToArray(arguments); +344 spyObj.mostRecentCall.object = this; +345 spyObj.mostRecentCall.args = args; +346 spyObj.argsForCall.push(args); +347 spyObj.calls.push({object: this, args: args}); +348 return spyObj.plan.apply(this, arguments); +349 }; +350 +351 var spy = new jasmine.Spy(name); +352 +353 for (var prop in spy) { +354 spyObj[prop] = spy[prop]; +355 } +356 +357 spyObj.reset(); +358 +359 return spyObj; +360 }; +361 +362 /** +363 * Determines whether an object is a spy. +364 * +365 * @param {jasmine.Spy|Object} putativeSpy +366 * @returns {Boolean} +367 */ +368 jasmine.isSpy = function(putativeSpy) { +369 return putativeSpy && putativeSpy.isSpy; +370 }; +371 +372 /** +373 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something +374 * large in one call. +375 * +376 * @param {String} baseName name of spy class +377 * @param {Array} methodNames array of names of methods to make spies 378 */ -379 var spyOn = function(obj, methodName) { -380 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -381 }; -382 -383 /** -384 * Creates a Jasmine spec that will be added to the current suite. -385 * -386 * // TODO: pending tests -387 * -388 * @example -389 * it('should be true', function() { -390 * expect(true).toEqual(true); -391 * }); -392 * -393 * @param {String} desc description of this specification -394 * @param {Function} func defines the preconditions and expectations of the spec -395 */ -396 var it = function(desc, func) { -397 return jasmine.getEnv().it(desc, func); -398 }; -399 -400 /** -401 * Creates a <em>disabled</em> Jasmine spec. -402 * -403 * A convenience method that allows existing specs to be disabled temporarily during development. -404 * -405 * @param {String} desc description of this specification -406 * @param {Function} func defines the preconditions and expectations of the spec -407 */ -408 var xit = function(desc, func) { -409 return jasmine.getEnv().xit(desc, func); -410 }; -411 -412 /** -413 * Starts a chain for a Jasmine expectation. -414 * -415 * It is passed an Object that is the actual value and should chain to one of the many -416 * jasmine.Matchers functions. +379 jasmine.createSpyObj = function(baseName, methodNames) { +380 if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { +381 throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); +382 } +383 var obj = {}; +384 for (var i = 0; i < methodNames.length; i++) { +385 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); +386 } +387 return obj; +388 }; +389 +390 jasmine.log = function(message) { +391 jasmine.getEnv().currentSpec.log(message); +392 }; +393 +394 /** +395 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. +396 * +397 * @example +398 * // spy example +399 * var foo = { +400 * not: function(bool) { return !bool; } +401 * } +402 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops +403 * +404 * @see jasmine.createSpy +405 * @param obj +406 * @param methodName +407 * @returns a Jasmine spy that can be chained with all spy methods +408 */ +409 var spyOn = function(obj, methodName) { +410 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +411 }; +412 +413 /** +414 * Creates a Jasmine spec that will be added to the current suite. +415 * +416 * // TODO: pending tests 417 * -418 * @param {Object} actual Actual value to test against and expected value -419 */ -420 var expect = function(actual) { -421 return jasmine.getEnv().currentSpec.expect(actual); -422 }; -423 -424 /** -425 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. -426 * -427 * @param {Function} func Function that defines part of a jasmine spec. -428 */ -429 var runs = function(func) { -430 jasmine.getEnv().currentSpec.runs(func); -431 }; -432 -433 /** -434 * Waits for a timeout before moving to the next runs()-defined block. -435 * @param {Number} timeout -436 */ -437 var waits = function(timeout) { -438 jasmine.getEnv().currentSpec.waits(timeout); -439 }; -440 -441 /** -442 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. -443 * -444 * @param {Number} timeout -445 * @param {Function} latchFunction -446 * @param {String} message -447 */ -448 var waitsFor = function(timeout, latchFunction, message) { -449 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); -450 }; -451 -452 /** -453 * A function that is called before each spec in a suite. -454 * -455 * Used for spec setup, including validating assumptions. +418 * @example +419 * it('should be true', function() { +420 * expect(true).toEqual(true); +421 * }); +422 * +423 * @param {String} desc description of this specification +424 * @param {Function} func defines the preconditions and expectations of the spec +425 */ +426 var it = function(desc, func) { +427 return jasmine.getEnv().it(desc, func); +428 }; +429 +430 /** +431 * Creates a <em>disabled</em> Jasmine spec. +432 * +433 * A convenience method that allows existing specs to be disabled temporarily during development. +434 * +435 * @param {String} desc description of this specification +436 * @param {Function} func defines the preconditions and expectations of the spec +437 */ +438 var xit = function(desc, func) { +439 return jasmine.getEnv().xit(desc, func); +440 }; +441 +442 /** +443 * Starts a chain for a Jasmine expectation. +444 * +445 * It is passed an Object that is the actual value and should chain to one of the many +446 * jasmine.Matchers functions. +447 * +448 * @param {Object} actual Actual value to test against and expected value +449 */ +450 var expect = function(actual) { +451 return jasmine.getEnv().currentSpec.expect(actual); +452 }; +453 +454 /** +455 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. 456 * -457 * @param {Function} beforeEachFunction +457 * @param {Function} func Function that defines part of a jasmine spec. 458 */ -459 var beforeEach = function(beforeEachFunction) { -460 jasmine.getEnv().beforeEach(beforeEachFunction); +459 var runs = function(func) { +460 jasmine.getEnv().currentSpec.runs(func); 461 }; 462 463 /** -464 * A function that is called after each spec in a suite. -465 * -466 * Used for restoring any state that is hijacked during spec execution. -467 * -468 * @param {Function} afterEachFunction -469 */ -470 var afterEach = function(afterEachFunction) { -471 jasmine.getEnv().afterEach(afterEachFunction); -472 }; -473 -474 /** -475 * Defines a suite of specifications. -476 * -477 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared -478 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization -479 * of setup in some tests. -480 * -481 * @example -482 * // TODO: a simple suite -483 * -484 * // TODO: a simple suite with a nested describe block -485 * -486 * @param {String} description A string, usually the class under test. -487 * @param {Function} specDefinitions function that defines several specs. +464 * Waits for a timeout before moving to the next runs()-defined block. +465 * @param {Number} timeout +466 */ +467 var waits = function(timeout) { +468 jasmine.getEnv().currentSpec.waits(timeout); +469 }; +470 +471 /** +472 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. +473 * +474 * @param {Number} timeout +475 * @param {Function} latchFunction +476 * @param {String} message +477 */ +478 var waitsFor = function(timeout, latchFunction, message) { +479 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +480 }; +481 +482 /** +483 * A function that is called before each spec in a suite. +484 * +485 * Used for spec setup, including validating assumptions. +486 * +487 * @param {Function} beforeEachFunction 488 */ -489 var describe = function(description, specDefinitions) { -490 return jasmine.getEnv().describe(description, specDefinitions); +489 var beforeEach = function(beforeEachFunction) { +490 jasmine.getEnv().beforeEach(beforeEachFunction); 491 }; 492 493 /** -494 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. +494 * A function that is called after each spec in a suite. 495 * -496 * @param {String} description A string, usually the class under test. -497 * @param {Function} specDefinitions function that defines several specs. -498 */ -499 var xdescribe = function(description, specDefinitions) { -500 return jasmine.getEnv().xdescribe(description, specDefinitions); -501 }; -502 +496 * Used for restoring any state that is hijacked during spec execution. +497 * +498 * @param {Function} afterEachFunction +499 */ +500 var afterEach = function(afterEachFunction) { +501 jasmine.getEnv().afterEach(afterEachFunction); +502 }; 503 -504 // Provide the XMLHttpRequest class for IE 5.x-6.x: -505 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { -506 try { -507 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); -508 } catch(e) { -509 } -510 try { -511 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); -512 } catch(e) { -513 } -514 try { -515 return new ActiveXObject("Msxml2.XMLHTTP"); -516 } catch(e) { -517 } -518 try { -519 return new ActiveXObject("Microsoft.XMLHTTP"); -520 } catch(e) { -521 } -522 throw new Error("This browser does not support XMLHttpRequest."); -523 } : XMLHttpRequest; -524 -525 /** -526 * Adds suite files to an HTML document so that they are executed, thus adding them to the current -527 * Jasmine environment. -528 * -529 * @param {String} url path to the file to include -530 * @param {Boolean} opt_global -531 */ -532 jasmine.include = function(url, opt_global) { -533 if (opt_global) { -534 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); -535 } else { -536 var xhr; -537 try { -538 xhr = new jasmine.XmlHttpRequest(); -539 xhr.open("GET", url, false); -540 xhr.send(null); -541 } catch(e) { -542 throw new Error("couldn't fetch " + url + ": " + e); -543 } -544 -545 return eval(xhr.responseText); -546 } -547 }; -548 \ No newline at end of file +504 /** +505 * Defines a suite of specifications. +506 * +507 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared +508 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization +509 * of setup in some tests. +510 * +511 * @example +512 * // TODO: a simple suite +513 * +514 * // TODO: a simple suite with a nested describe block +515 * +516 * @param {String} description A string, usually the class under test. +517 * @param {Function} specDefinitions function that defines several specs. +518 */ +519 var describe = function(description, specDefinitions) { +520 return jasmine.getEnv().describe(description, specDefinitions); +521 }; +522 +523 /** +524 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. +525 * +526 * @param {String} description A string, usually the class under test. +527 * @param {Function} specDefinitions function that defines several specs. +528 */ +529 var xdescribe = function(description, specDefinitions) { +530 return jasmine.getEnv().xdescribe(description, specDefinitions); +531 }; +532 +533 +534 // Provide the XMLHttpRequest class for IE 5.x-6.x: +535 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { +536 try { +537 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); +538 } catch(e) { +539 } +540 try { +541 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); +542 } catch(e) { +543 } +544 try { +545 return new ActiveXObject("Msxml2.XMLHTTP"); +546 } catch(e) { +547 } +548 try { +549 return new ActiveXObject("Microsoft.XMLHTTP"); +550 } catch(e) { +551 } +552 throw new Error("This browser does not support XMLHttpRequest."); +553 } : XMLHttpRequest; +554 +555 /** +556 * Adds suite files to an HTML document so that they are executed, thus adding them to the current +557 * Jasmine environment. +558 * +559 * @param {String} url path to the file to include +560 * @param {Boolean} opt_global +561 */ +562 jasmine.include = function(url, opt_global) { +563 if (opt_global) { +564 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); +565 } else { +566 var xhr; +567 try { +568 xhr = new jasmine.XmlHttpRequest(); +569 xhr.open("GET", url, false); +570 xhr.send(null); +571 } catch(e) { +572 throw new Error("couldn't fetch " + url + ": " + e); +573 } +574 +575 return eval(xhr.responseText); +576 } +577 }; +578 \ No newline at end of file diff --git a/lib/jasmine-0.10.1.js b/lib/jasmine-0.10.2.js similarity index 99% rename from lib/jasmine-0.10.1.js rename to lib/jasmine-0.10.2.js index 73abc10..05af921 100644 --- a/lib/jasmine-0.10.1.js +++ b/lib/jasmine-0.10.2.js @@ -2313,6 +2313,6 @@ window.clearInterval = function(timeoutKey) { jasmine.version_= { "major": 0, "minor": 10, - "build": 1, - "revision": 1268969514 + "build": 2, + "revision": 1268969696 }; diff --git a/src/version.json b/src/version.json index a0d438c..1cd3313 100644 --- a/src/version.json +++ b/src/version.json @@ -1,5 +1,5 @@ { "major": 0, "minor": 10, - "build": 1 + "build": 2 } \ No newline at end of file