diff --git a/doc/files.html b/doc/files.html index dfdecfe..50ff90b 100644 --- a/doc/files.html +++ b/doc/files.html @@ -454,7 +454,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index fa86084..1aa2b28 100644 --- a/doc/index.html +++ b/doc/index.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 57f29d3..6e50334 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index a04e2c9..73c5e7d 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Clock.html b/doc/symbols/jasmine.Clock.html index fd7c165..627ae47 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 40efbdd..35625fc 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index ca02c07..61255dd 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index 4ec8408..bc20fdc 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -304,7 +304,7 @@ ul.inheritsList   -
message(expected) +
message()
@@ -403,7 +403,7 @@ ul.inheritsList   -
toContain(item) +
toContain(expected)
Matcher that checks that the expected item is an element in the actual Array.
@@ -421,7 +421,7 @@ ul.inheritsList   -
toMatch(reg_exp) +
toMatch(expected)
Matcher that compares the actual to the expected using a regular expression.
@@ -439,7 +439,7 @@ ul.inheritsList   -
toNotContain(item) +
toNotContain(expected)
Matcher that checks that the expected item is NOT an element in the actual Array.
@@ -457,7 +457,7 @@ ul.inheritsList   -
toNotMatch(reg_exp) +
toNotMatch(expected)
Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
@@ -466,7 +466,7 @@ ul.inheritsList   -
toThrow(expectedException) +
toThrow(expected)
Matcher that checks that the expected exception was thrown by the actual.
@@ -508,6 +508,15 @@ ul.inheritsList + + <static>   + +
jasmine.Matchers.wrapInto_(prototype, matchersClass) +
+
+ + + @@ -661,7 +670,7 @@ ul.inheritsList
- message(expected) + message()
@@ -673,17 +682,6 @@ ul.inheritsList -
-
Parameters:
- -
- expected - -
-
- -
- @@ -1014,7 +1012,7 @@ ul.inheritsList
- toContain(item) + toContain(expected)
@@ -1030,7 +1028,7 @@ ul.inheritsList
Parameters:
- {Object} item + {Object} expected
@@ -1086,7 +1084,7 @@ ul.inheritsList
- toMatch(reg_exp) + toMatch(expected)
@@ -1103,7 +1101,7 @@ a pattern or a String.
Parameters:
- reg_exp + expected
@@ -1159,7 +1157,7 @@ a pattern or a String.
- toNotContain(item) + toNotContain(expected)
@@ -1175,7 +1173,7 @@ a pattern or a String.
Parameters:
- {Object} item + {Object} expected
@@ -1231,7 +1229,7 @@ a pattern or a String.
- toNotMatch(reg_exp) + toNotMatch(expected)
@@ -1247,7 +1245,7 @@ a pattern or a String.
Parameters:
- reg_exp + expected
@@ -1267,7 +1265,7 @@ a pattern or a String.
- toThrow(expectedException) + toThrow(expected)
@@ -1283,7 +1281,7 @@ a pattern or a String.
Parameters:
- {String} expectedException + {String} expected
@@ -1401,6 +1399,48 @@ a pattern or a String. +
+ + +
<static> + + + jasmine.Matchers.wrapInto_(prototype, matchersClass) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ prototype + +
+
+ +
+ matchersClass + +
+
+ +
+ + + + + + + + @@ -1415,7 +1455,7 @@ a pattern or a String.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 8583a03..36fc55b 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 395225e..cff8abc 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 3646e49..3420f20 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index c3ac98a..ba336dc 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 3c6473c..f411d58 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -1253,7 +1253,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index 0cb83ac..37667bc 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index d5f40c6..11d664c 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 835bd0f..6464a3f 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index bb10c02..445374f 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 Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/src/src_Env.js.html b/doc/symbols/src/src_Env.js.html index 7b46e68..9c858a7 100644 --- a/doc/symbols/src/src_Env.js.html +++ b/doc/symbols/src/src_Env.js.html @@ -33,211 +33,208 @@ 26 }; 27 jasmine.util.inherit(this.matchersClass, jasmine.Matchers); 28 - 29 for (var methodName in jasmine.Matchers.prototype) { - 30 var orig = jasmine.Matchers.prototype[methodName]; - 31 this.matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); - 32 } - 33 }; - 34 - 35 - 36 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; - 37 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; - 38 jasmine.Env.prototype.setInterval = jasmine.setInterval; - 39 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; - 40 - 41 /** - 42 * @returns an object containing jasmine version build info, if set. - 43 */ - 44 jasmine.Env.prototype.version = function () { - 45 if (jasmine.version_) { - 46 return jasmine.version_; - 47 } else { - 48 throw new Error('Version not set'); - 49 } - 50 }; - 51 - 52 /** - 53 * @returns a sequential integer starting at 0 - 54 */ - 55 jasmine.Env.prototype.nextSpecId = function () { - 56 return this.nextSpecId_++; - 57 }; - 58 - 59 /** - 60 * @returns a sequential integer starting at 0 - 61 */ - 62 jasmine.Env.prototype.nextSuiteId = function () { - 63 return this.nextSuiteId_++; - 64 }; - 65 - 66 /** - 67 * Register a reporter to receive status updates from Jasmine. - 68 * @param {jasmine.Reporter} reporter An object which will receive status updates. - 69 */ - 70 jasmine.Env.prototype.addReporter = function(reporter) { - 71 this.reporter.addReporter(reporter); - 72 }; - 73 - 74 jasmine.Env.prototype.execute = function() { - 75 this.currentRunner_.execute(); - 76 }; + 29 jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); + 30 }; + 31 + 32 + 33 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; + 34 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; + 35 jasmine.Env.prototype.setInterval = jasmine.setInterval; + 36 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; + 37 + 38 /** + 39 * @returns an object containing jasmine version build info, if set. + 40 */ + 41 jasmine.Env.prototype.version = function () { + 42 if (jasmine.version_) { + 43 return jasmine.version_; + 44 } else { + 45 throw new Error('Version not set'); + 46 } + 47 }; + 48 + 49 /** + 50 * @returns a sequential integer starting at 0 + 51 */ + 52 jasmine.Env.prototype.nextSpecId = function () { + 53 return this.nextSpecId_++; + 54 }; + 55 + 56 /** + 57 * @returns a sequential integer starting at 0 + 58 */ + 59 jasmine.Env.prototype.nextSuiteId = function () { + 60 return this.nextSuiteId_++; + 61 }; + 62 + 63 /** + 64 * Register a reporter to receive status updates from Jasmine. + 65 * @param {jasmine.Reporter} reporter An object which will receive status updates. + 66 */ + 67 jasmine.Env.prototype.addReporter = function(reporter) { + 68 this.reporter.addReporter(reporter); + 69 }; + 70 + 71 jasmine.Env.prototype.execute = function() { + 72 this.currentRunner_.execute(); + 73 }; + 74 + 75 jasmine.Env.prototype.describe = function(description, specDefinitions) { + 76 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); 77 - 78 jasmine.Env.prototype.describe = function(description, specDefinitions) { - 79 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); - 80 - 81 var parentSuite = this.currentSuite; - 82 if (parentSuite) { - 83 parentSuite.add(suite); - 84 } else { - 85 this.currentRunner_.add(suite); - 86 } - 87 - 88 this.currentSuite = suite; - 89 - 90 specDefinitions.call(suite); - 91 - 92 this.currentSuite = parentSuite; + 78 var parentSuite = this.currentSuite; + 79 if (parentSuite) { + 80 parentSuite.add(suite); + 81 } else { + 82 this.currentRunner_.add(suite); + 83 } + 84 + 85 this.currentSuite = suite; + 86 + 87 specDefinitions.call(suite); + 88 + 89 this.currentSuite = parentSuite; + 90 + 91 return suite; + 92 }; 93 - 94 return suite; - 95 }; - 96 - 97 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { - 98 if (this.currentSuite) { - 99 this.currentSuite.beforeEach(beforeEachFunction); -100 } else { -101 this.currentRunner_.beforeEach(beforeEachFunction); -102 } -103 }; -104 -105 jasmine.Env.prototype.currentRunner = function () { -106 return this.currentRunner_; -107 }; -108 -109 jasmine.Env.prototype.afterEach = function(afterEachFunction) { -110 if (this.currentSuite) { -111 this.currentSuite.afterEach(afterEachFunction); -112 } else { -113 this.currentRunner_.afterEach(afterEachFunction); -114 } -115 -116 }; -117 -118 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { -119 return { -120 execute: function() { -121 } -122 }; -123 }; -124 -125 jasmine.Env.prototype.it = function(description, func) { -126 var spec = new jasmine.Spec(this, this.currentSuite, description); -127 this.currentSuite.add(spec); -128 this.currentSpec = spec; -129 -130 if (func) { -131 spec.runs(func); -132 } + 94 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { + 95 if (this.currentSuite) { + 96 this.currentSuite.beforeEach(beforeEachFunction); + 97 } else { + 98 this.currentRunner_.beforeEach(beforeEachFunction); + 99 } +100 }; +101 +102 jasmine.Env.prototype.currentRunner = function () { +103 return this.currentRunner_; +104 }; +105 +106 jasmine.Env.prototype.afterEach = function(afterEachFunction) { +107 if (this.currentSuite) { +108 this.currentSuite.afterEach(afterEachFunction); +109 } else { +110 this.currentRunner_.afterEach(afterEachFunction); +111 } +112 +113 }; +114 +115 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +116 return { +117 execute: function() { +118 } +119 }; +120 }; +121 +122 jasmine.Env.prototype.it = function(description, func) { +123 var spec = new jasmine.Spec(this, this.currentSuite, description); +124 this.currentSuite.add(spec); +125 this.currentSpec = spec; +126 +127 if (func) { +128 spec.runs(func); +129 } +130 +131 return spec; +132 }; 133 -134 return spec; -135 }; -136 -137 jasmine.Env.prototype.xit = function(desc, func) { -138 return { -139 id: this.nextSpecId(), -140 runs: function() { -141 } -142 }; -143 }; -144 -145 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { -146 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { -147 return true; -148 } +134 jasmine.Env.prototype.xit = function(desc, func) { +135 return { +136 id: this.nextSpecId(), +137 runs: function() { +138 } +139 }; +140 }; +141 +142 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { +143 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { +144 return true; +145 } +146 +147 a.__Jasmine_been_here_before__ = b; +148 b.__Jasmine_been_here_before__ = a; 149 -150 a.__Jasmine_been_here_before__ = b; -151 b.__Jasmine_been_here_before__ = a; -152 -153 var hasKey = function(obj, keyName) { -154 return obj != null && obj[keyName] !== jasmine.undefined; -155 }; -156 -157 for (var property in b) { -158 if (!hasKey(a, property) && hasKey(b, property)) { -159 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); -160 } -161 } -162 for (property in a) { -163 if (!hasKey(b, property) && hasKey(a, property)) { -164 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); -165 } -166 } -167 for (property in b) { -168 if (property == '__Jasmine_been_here_before__') continue; -169 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { -170 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); -171 } -172 } -173 -174 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { -175 mismatchValues.push("arrays were not the same length"); -176 } -177 -178 delete a.__Jasmine_been_here_before__; -179 delete b.__Jasmine_been_here_before__; -180 return (mismatchKeys.length == 0 && mismatchValues.length == 0); -181 }; -182 -183 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { -184 mismatchKeys = mismatchKeys || []; -185 mismatchValues = mismatchValues || []; -186 -187 if (a === b) return true; -188 -189 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { -190 return (a == jasmine.undefined && b == jasmine.undefined); -191 } -192 -193 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -194 return a === b; -195 } -196 -197 if (a instanceof Date && b instanceof Date) { -198 return a.getTime() == b.getTime(); -199 } -200 -201 if (a instanceof jasmine.Matchers.Any) { -202 return a.matches(b); -203 } -204 -205 if (b instanceof jasmine.Matchers.Any) { -206 return b.matches(a); -207 } -208 -209 if (typeof a === "object" && typeof b === "object") { -210 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -211 } -212 -213 for (var i = 0; i < this.equalityTesters_.length; i++) { -214 var equalityTester = this.equalityTesters_[i]; -215 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -216 if (result !== jasmine.undefined) return result; -217 } -218 -219 //Straight check -220 return (a === b); -221 }; -222 -223 jasmine.Env.prototype.contains_ = function(haystack, needle) { -224 if (jasmine.isArray_(haystack)) { -225 for (var i = 0; i < haystack.length; i++) { -226 if (this.equals_(haystack[i], needle)) return true; -227 } -228 return false; -229 } -230 return haystack.indexOf(needle) >= 0; -231 }; -232 -233 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -234 this.equalityTesters_.push(equalityTester); -235 }; -236 \ No newline at end of file +150 var hasKey = function(obj, keyName) { +151 return obj != null && obj[keyName] !== jasmine.undefined; +152 }; +153 +154 for (var property in b) { +155 if (!hasKey(a, property) && hasKey(b, property)) { +156 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); +157 } +158 } +159 for (property in a) { +160 if (!hasKey(b, property) && hasKey(a, property)) { +161 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); +162 } +163 } +164 for (property in b) { +165 if (property == '__Jasmine_been_here_before__') continue; +166 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { +167 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); +168 } +169 } +170 +171 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { +172 mismatchValues.push("arrays were not the same length"); +173 } +174 +175 delete a.__Jasmine_been_here_before__; +176 delete b.__Jasmine_been_here_before__; +177 return (mismatchKeys.length == 0 && mismatchValues.length == 0); +178 }; +179 +180 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +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); +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; +214 } +215 +216 //Straight check +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 diff --git a/doc/symbols/src/src_Matchers.js.html b/doc/symbols/src/src_Matchers.js.html index 0000319..20f9391 100644 --- a/doc/symbols/src/src_Matchers.js.html +++ b/doc/symbols/src/src_Matchers.js.html @@ -15,307 +15,314 @@ 8 this.env = env; 9 this.actual = actual; 10 this.spec = spec; - 11 }; - 12 - 13 jasmine.Matchers.pp = function(str) { - 14 return jasmine.util.htmlEscape(jasmine.pp(str)); - 15 }; - 16 - 17 jasmine.Matchers.prototype.report = function(result, failing_message, details) { - 18 var expectationResult = new jasmine.ExpectationResult({ - 19 passed: result, - 20 message: failing_message, - 21 details: details - 22 }); - 23 this.spec.addMatcherResult(expectationResult); - 24 return result; - 25 }; - 26 - 27 jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { - 28 return function() { - 29 var matcherArgs = jasmine.util.argsToArray(arguments); - 30 var result = matcherFunction.apply(this, arguments); - 31 var message; - 32 if (!result) { - 33 if (this.message) { - 34 message = this.message.apply(this, arguments); - 35 } else { - 36 var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); - 37 message = "Expected " + jasmine.pp(this.actual) + " " + englishyPredicate; - 38 if (matcherArgs.length > 0) { - 39 for (var i = 0; i < matcherArgs.length; i++) { - 40 if (i > 0) message += ","; - 41 message += " " + jasmine.pp(matcherArgs[i]); - 42 } - 43 } - 44 message += "."; - 45 } - 46 } - 47 var expectationResult = new jasmine.ExpectationResult({ - 48 matcherName: matcherName, - 49 passed: result, - 50 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], - 51 actual: this.actual, - 52 message: message - 53 }); - 54 this.spec.addMatcherResult(expectationResult); - 55 return result; - 56 }; - 57 }; - 58 - 59 - 60 - 61 - 62 /** - 63 * toBe: compares the actual to the expected using === - 64 * @param expected - 65 */ - 66 - 67 jasmine.Matchers.prototype.toBe = function(expected) { - 68 return this.actual === expected; - 69 }; - 70 - 71 /** - 72 * toNotBe: compares the actual to the expected using !== - 73 * @param expected - 74 */ - 75 jasmine.Matchers.prototype.toNotBe = function(expected) { - 76 return this.actual !== expected; - 77 }; - 78 - 79 /** - 80 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. - 81 * - 82 * @param expected - 83 */ + 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 jasmine.Matchers.prototype.toEqual = function(expected) { - 86 return this.env.equals_(this.actual, expected); - 87 }; - 88 - 89 /** - 90 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual - 91 * @param expected - 92 */ - 93 jasmine.Matchers.prototype.toNotEqual = function(expected) { - 94 return !this.env.equals_(this.actual, expected); - 95 }; - 96 - 97 /** - 98 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes - 99 * a pattern or a String. -100 * -101 * @param reg_exp -102 */ -103 jasmine.Matchers.prototype.toMatch = function(expected) { -104 return new RegExp(expected).test(this.actual); -105 }; -106 -107 /** -108 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -109 * @param reg_exp -110 */ -111 jasmine.Matchers.prototype.toNotMatch = function(expected) { -112 return !(new RegExp(expected).test(this.actual)); -113 }; -114 -115 /** -116 * Matcher that compares the actual to jasmine.undefined. -117 */ -118 jasmine.Matchers.prototype.toBeDefined = function() { -119 return (this.actual !== jasmine.undefined); -120 }; -121 -122 /** -123 * Matcher that compares the actual to jasmine.undefined. -124 */ -125 jasmine.Matchers.prototype.toBeUndefined = function() { -126 return (this.actual === jasmine.undefined); -127 }; -128 -129 /** -130 * Matcher that compares the actual to null. -131 */ -132 jasmine.Matchers.prototype.toBeNull = function() { -133 return (this.actual === null); -134 }; -135 -136 /** -137 * Matcher that boolean not-nots the actual. -138 */ -139 jasmine.Matchers.prototype.toBeTruthy = function() { -140 return !!this.actual; -141 }; -142 -143 -144 /** -145 * Matcher that boolean nots the actual. -146 */ -147 jasmine.Matchers.prototype.toBeFalsy = function() { -148 return !this.actual; -149 }; -150 -151 /** -152 * Matcher that checks to see if the actual, a Jasmine spy, was called. -153 */ -154 jasmine.Matchers.prototype.wasCalled = function() { -155 if (arguments.length > 0) { -156 throw new Error('wasCalled does not take arguments, use wasCalledWith'); -157 } -158 -159 if (!jasmine.isSpy(this.actual)) { -160 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -161 } -162 -163 this.message = function() { -164 return "Expected spy " + this.actual.identity + " to have been called."; -165 }; -166 -167 return this.actual.wasCalled; -168 }; -169 -170 /** -171 * Matcher that checks to see if the actual, a Jasmine spy, was not called. -172 */ -173 jasmine.Matchers.prototype.wasNotCalled = function() { -174 if (arguments.length > 0) { -175 throw new Error('wasNotCalled does not take arguments'); -176 } -177 -178 if (!jasmine.isSpy(this.actual)) { -179 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -180 } -181 -182 this.message = function() { -183 return "Expected spy " + this.actual.identity + " to not have been called."; -184 }; -185 -186 return !this.actual.wasCalled; -187 }; -188 -189 /** -190 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. -191 * -192 * @example -193 * -194 */ -195 jasmine.Matchers.prototype.wasCalledWith = function() { -196 if (!jasmine.isSpy(this.actual)) { -197 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -198 } -199 -200 this.message = function() { -201 if (this.actual.callCount == 0) { -202 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; -203 } else { -204 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); -205 } -206 }; -207 -208 return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); -209 }; -210 -211 jasmine.Matchers.prototype.wasNotCalledWith = function() { -212 if (!jasmine.isSpy(this.actual)) { -213 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -214 } -215 -216 this.message = function() { -217 return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; -218 }; -219 -220 return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); -221 }; -222 -223 /** -224 * Matcher that checks that the expected item is an element in the actual Array. -225 * -226 * @param {Object} item -227 */ -228 jasmine.Matchers.prototype.toContain = function(expected) { -229 return this.env.contains_(this.actual, expected); -230 }; -231 -232 /** -233 * Matcher that checks that the expected item is NOT an element in the actual Array. -234 * -235 * @param {Object} item -236 */ -237 jasmine.Matchers.prototype.toNotContain = function(expected) { -238 return !this.env.contains_(this.actual, expected); -239 }; -240 -241 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -242 return this.actual < expected; + 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. +130 */ +131 jasmine.Matchers.prototype.toBeDefined = function() { +132 return (this.actual !== jasmine.undefined); +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 +156 +157 /** +158 * Matcher that boolean nots the actual. +159 */ +160 jasmine.Matchers.prototype.toBeFalsy = function() { +161 return !this.actual; +162 }; +163 +164 /** +165 * Matcher that checks to see if the actual, a Jasmine spy, was called. +166 */ +167 jasmine.Matchers.prototype.wasCalled = function() { +168 if (arguments.length > 0) { +169 throw new Error('wasCalled does not take arguments, use wasCalledWith'); +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'); +189 } +190 +191 if (!jasmine.isSpy(this.actual)) { +192 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +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() { +225 if (!jasmine.isSpy(this.actual)) { +226 throw new Error('Expected a spy, but got ' + jasmine.Matchers.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 }; +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 }; 244 -245 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -246 return this.actual > expected; -247 }; -248 -249 /** -250 * Matcher that checks that the expected exception was thrown by the actual. -251 * -252 * @param {String} expectedException -253 */ -254 jasmine.Matchers.prototype.toThrow = function(expected) { -255 function getException_(actual, expected) { -256 var exception; -257 if (typeof actual != 'function') { -258 throw new Error('Actual is not a function'); -259 } -260 try { -261 actual(); -262 } catch (e) { -263 exception = e; -264 } -265 return exception; -266 } -267 +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 = getException_(this.actual, expected); -270 if (exception) { -271 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +269 var exception; +270 if (typeof this.actual != 'function') { +271 throw new Error('Actual is not a function'); 272 } -273 -274 this.message = function(expected) { -275 var exception = getException_(this.actual, expected); -276 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -277 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); -278 } else { -279 return "Expected function to throw an exception."; -280 } -281 }; -282 -283 return result; -284 }; -285 -286 jasmine.Matchers.Any = function(expectedClass) { -287 this.expectedClass = expectedClass; -288 }; +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 jasmine.Matchers.Any.prototype.matches = function(other) { -291 if (this.expectedClass == String) { -292 return typeof other == 'string' || other instanceof String; -293 } -294 -295 if (this.expectedClass == Number) { -296 return typeof other == 'number' || other instanceof Number; -297 } -298 -299 if (this.expectedClass == Function) { -300 return typeof other == 'function' || other instanceof Function; -301 } -302 -303 if (this.expectedClass == Object) { -304 return typeof other == 'object'; -305 } -306 -307 return other instanceof this.expectedClass; -308 }; +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 } +305 +306 if (this.expectedClass == Function) { +307 return typeof other == 'function' || other instanceof Function; +308 } 309 -310 jasmine.Matchers.Any.prototype.toString = function() { -311 return '<jasmine.any(' + this.expectedClass + ')>'; -312 }; +310 if (this.expectedClass == Object) { +311 return typeof other == 'object'; +312 } 313 -314 \ No newline at end of file +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 diff --git a/doc/symbols/src/src_Spec.js.html b/doc/symbols/src/src_Spec.js.html index 2523022..8b69c25 100644 --- a/doc/symbols/src/src_Spec.js.html +++ b/doc/symbols/src/src_Spec.js.html @@ -105,109 +105,107 @@ 98 parent.apply(this, arguments); 99 }; 100 jasmine.util.inherit(newMatchersClass, parent); -101 for (var method in matchersPrototype) { -102 newMatchersClass.prototype[method] = matchersPrototype[method]; -103 } -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 }; +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) { 118 -119 jasmine.Spec.prototype.after = function(doAfter, test) { -120 -121 if (this.queue.isRunning()) { -122 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -123 } else { -124 this.afterCallbacks.unshift(doAfter); -125 } -126 }; -127 -128 jasmine.Spec.prototype.execute = function(onComplete) { -129 var spec = this; -130 if (!spec.env.specFilter(spec)) { -131 spec.results_.skipped = true; -132 spec.finish(onComplete); -133 return; -134 } -135 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +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.env.currentSpec = spec; +137 spec.addBeforesAndAftersToQueue(); 138 -139 spec.addBeforesAndAftersToQueue(); -140 -141 spec.queue.start(function () { -142 spec.finish(onComplete); -143 }); -144 }; -145 -146 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -147 var runner = this.env.currentRunner(); -148 for (var suite = this.suite; suite; suite = suite.parentSuite) { -149 for (var i = 0; i < suite.before_.length; i++) { -150 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -151 } -152 } -153 for (var i = 0; i < runner.before_.length; i++) { -154 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -155 } -156 for (i = 0; i < this.afterCallbacks.length; i++) { -157 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -158 } -159 for (suite = this.suite; suite; suite = suite.parentSuite) { -160 for (var i = 0; i < suite.after_.length; i++) { -161 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -162 } -163 } -164 for (var i = 0; i < runner.after_.length; i++) { -165 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -166 } -167 }; -168 -169 jasmine.Spec.prototype.explodes = function() { -170 throw 'explodes function should not have been called'; -171 }; -172 -173 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -174 if (obj == jasmine.undefined) { -175 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -176 } -177 -178 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { -179 throw methodName + '() method does not exist'; -180 } -181 -182 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -183 throw new Error(methodName + ' has already been spied upon'); -184 } +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)); +153 } +154 for (i = 0; i < this.afterCallbacks.length; i++) { +155 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[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)); +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 var spyObj = jasmine.createSpy(methodName); -187 -188 this.spies_.push(spyObj); -189 spyObj.baseObj = obj; -190 spyObj.methodName = methodName; -191 spyObj.originalValue = obj[methodName]; +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 obj[methodName] = spyObj; -194 -195 return spyObj; -196 }; -197 -198 jasmine.Spec.prototype.removeAllSpies = function() { -199 for (var i = 0; i < this.spies_.length; i++) { -200 var spy = this.spies_[i]; -201 spy.baseObj[spy.methodName] = spy.originalValue; -202 } -203 this.spies_ = []; -204 }; -205 -206 \ No newline at end of file +193 return spyObj; +194 }; +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 diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 850daae..bb7547e 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -640,10 +640,7 @@ jasmine.Env = function() { }; jasmine.util.inherit(this.matchersClass, jasmine.Matchers); - for (var methodName in jasmine.Matchers.prototype) { - var orig = jasmine.Matchers.prototype[methodName]; - this.matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); - } + jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); }; @@ -1009,13 +1006,18 @@ jasmine.Matchers = function(env, actual, spec) { this.env = env; this.actual = actual; this.spec = spec; + this.reportWasCalled_ = false; }; jasmine.Matchers.pp = function(str) { return jasmine.util.htmlEscape(jasmine.pp(str)); }; +/** @deprecated */ jasmine.Matchers.prototype.report = function(result, failing_message, details) { +// todo first: report deprecation warning [xw] +// todo later: throw new Error("As of jasmine 0.xx, custom matchers must be implemented differently -- please see jasmine docs"); + this.reportWasCalled_ = true; var expectationResult = new jasmine.ExpectationResult({ passed: result, message: failing_message, @@ -1025,10 +1027,20 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) { return result; }; +jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { + for (var methodName in prototype) { + if (methodName == 'report') continue; + var orig = prototype[methodName]; + matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); + } +}; + jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { return function() { var matcherArgs = jasmine.util.argsToArray(arguments); var result = matcherFunction.apply(this, arguments); + if (this.reportWasCalled_) return result; + var message; if (!result) { if (this.message) { @@ -1064,7 +1076,6 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { * toBe: compares the actual to the expected using === * @param expected */ - jasmine.Matchers.prototype.toBe = function(expected) { return this.actual === expected; }; @@ -1082,7 +1093,6 @@ jasmine.Matchers.prototype.toNotBe = function(expected) { * * @param expected */ - jasmine.Matchers.prototype.toEqual = function(expected) { return this.env.equals_(this.actual, expected); }; @@ -1099,7 +1109,7 @@ jasmine.Matchers.prototype.toNotEqual = function(expected) { * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes * a pattern or a String. * - * @param reg_exp + * @param expected */ jasmine.Matchers.prototype.toMatch = function(expected) { return new RegExp(expected).test(this.actual); @@ -1107,7 +1117,7 @@ jasmine.Matchers.prototype.toMatch = function(expected) { /** * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch - * @param reg_exp + * @param expected */ jasmine.Matchers.prototype.toNotMatch = function(expected) { return !(new RegExp(expected).test(this.actual)); @@ -1224,7 +1234,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() { /** * Matcher that checks that the expected item is an element in the actual Array. * - * @param {Object} item + * @param {Object} expected */ jasmine.Matchers.prototype.toContain = function(expected) { return this.env.contains_(this.actual, expected); @@ -1233,7 +1243,7 @@ jasmine.Matchers.prototype.toContain = function(expected) { /** * Matcher that checks that the expected item is NOT an element in the actual Array. * - * @param {Object} item + * @param {Object} expected */ jasmine.Matchers.prototype.toNotContain = function(expected) { return !this.env.contains_(this.actual, expected); @@ -1250,32 +1260,26 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { /** * Matcher that checks that the expected exception was thrown by the actual. * - * @param {String} expectedException + * @param {String} expected */ jasmine.Matchers.prototype.toThrow = function(expected) { - function getException_(actual, expected) { - var exception; - if (typeof actual != 'function') { - throw new Error('Actual is not a function'); - } - try { - actual(); - } catch (e) { - exception = e; - } - return exception; - } - var result = false; - var exception = getException_(this.actual, expected); + var exception; + if (typeof this.actual != 'function') { + throw new Error('Actual is not a function'); + } + try { + this.actual(); + } catch (e) { + exception = e; + } if (exception) { result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); } - this.message = function(expected) { - var exception = getException_(this.actual, expected); + this.message = function() { if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { - return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); + return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); } else { return "Expected function to throw an exception."; } @@ -1847,9 +1851,7 @@ jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { parent.apply(this, arguments); }; jasmine.util.inherit(newMatchersClass, parent); - for (var method in matchersPrototype) { - newMatchersClass.prototype[method] = matchersPrototype[method]; - } + jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); this.matchersClass = newMatchersClass; }; @@ -2255,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1261632445 + "revision": 1261768736 };