diff --git a/doc/files.html b/doc/files.html index b4680cbd..9507e4bd 100644 --- a/doc/files.html +++ b/doc/files.html @@ -272,7 +272,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 62be71ac..902a0685 100644 --- a/doc/index.html +++ b/doc/index.html @@ -308,7 +308,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 154e7f03..1bd01668 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -910,7 +910,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 09a203c1..e3639887 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -341,7 +341,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 33e4b8f4..5af7b659 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -509,7 +509,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index df2a283b..8a28693e 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -318,7 +318,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index 5293655b..b7ba5e06 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -269,33 +269,6 @@ ul.inheritsList - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
<static>   -
jasmine.Matchers.addMatcher(expected, options) -
-
Matcher that compares the actual to the expected using ===.
-
- - - - @@ -357,53 +330,6 @@ ul.inheritsList -
- Method Detail -
- - -
<static> - - - jasmine.Matchers.addMatcher(expected, options) - -
-
- Matcher that compares the actual to the expected using ===. - - -
- - - - -
-
Parameters:
- -
- expected - -
-
- -
- options - -
-
- -
- - - - - - - - - - - @@ -415,7 +341,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 65e21e9b..abe1c080 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -318,7 +318,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index b90b1151..4b2881c0 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -702,7 +702,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 4680919d..4ed48248 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -318,7 +318,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index 84c84e93..9a19c3d8 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -329,7 +329,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 0a7b33e6..897b5435 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -341,7 +341,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index a8d391b7..b13fb027 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -847,7 +847,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index 30053d61..130c2e4e 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -347,7 +347,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index fac89de3..48e9e325 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -762,7 +762,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:29 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 2b93d8e1..1c11d5be 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -318,7 +318,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 20:33:30 GMT-0700 (PDT)
diff --git a/doc/symbols/src/lib_jasmine-0.10.0.js.html b/doc/symbols/src/lib_jasmine-0.10.0.js.html index 7ce6797c..1c07567d 100644 --- a/doc/symbols/src/lib_jasmine-0.10.0.js.html +++ b/doc/symbols/src/lib_jasmine-0.10.0.js.html @@ -543,7 +543,7 @@ 536 "major": 0, 537 "minor": 10, 538 "build": 0, -539 "revision": 1256870671 +539 "revision": 1256873185 540 }; 541 /** 542 * @namespace @@ -1010,1295 +1010,1288 @@ 1003 return result; 1004 }; 1005 -1006 /** -1007 * Matcher that compares the actual to the expected using ===. -1008 * -1009 * @param expected -1010 */ -1011 -1012 -1013 jasmine.Matchers.addMatcher = function(matcherName, options) { -1014 jasmine.Matchers.prototype[matcherName] = function () { -1015 jasmine.util.extend(this, options); -1016 var expected = jasmine.util.argsToArray(arguments); -1017 var args = [this.actual].concat(expected); -1018 var result = options.test.apply(this, args); -1019 var message; -1020 if (!result) { -1021 message = options.message.apply(this, args); -1022 } -1023 var expectationResult = new jasmine.ExpectationResult({ -1024 matcherName: matcherName, -1025 passed: result, -1026 expected: expected, -1027 actual: this.actual, -1028 message: message -1029 }); -1030 this.spec.addMatcherResult(expectationResult); -1031 return result; -1032 }; -1033 }; -1034 -1035 -1036 /** -1037 * toBe: compares the actual to the expected using === -1038 * @param expected -1039 */ -1040 -1041 jasmine.Matchers.addMatcher('toBe', { -1042 test: function (actual, expected) { -1043 return actual === expected; -1044 }, -1045 message: function(actual, expected) { -1046 return "Expected " + jasmine.pp(actual) + " to be " + jasmine.pp(expected); -1047 } -1048 }); -1049 -1050 /** -1051 * toNotBe: compares the actual to the expected using !== -1052 * @param expected -1053 */ -1054 jasmine.Matchers.addMatcher('toNotBe', { -1055 test: function (actual, expected) { -1056 return actual !== expected; -1057 }, -1058 message: function(actual, expected) { -1059 return "Expected " + jasmine.pp(actual) + " to not be " + jasmine.pp(expected); -1060 } -1061 }); -1062 -1063 /** -1064 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. -1065 * -1066 * @param expected -1067 */ -1068 -1069 jasmine.Matchers.addMatcher('toEqual', { -1070 test: function (actual, expected) { -1071 return this.env.equals_(actual, expected); -1072 }, -1073 message: function(actual, expected) { -1074 return "Expected " + jasmine.pp(actual) + " to equal " + jasmine.pp(expected); -1075 } -1076 }); -1077 -1078 /** -1079 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual -1080 * @param expected -1081 */ -1082 jasmine.Matchers.addMatcher('toNotEqual', { -1083 test: function (actual, expected) { -1084 return !this.env.equals_(actual, expected); -1085 }, -1086 message: function(actual, expected) { -1087 return "Expected " + jasmine.pp(actual) + " to not equal " + jasmine.pp(expected); -1088 } -1089 }); -1090 -1091 /** -1092 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -1093 * a pattern or a String. -1094 * -1095 * @param reg_exp -1096 */ -1097 jasmine.Matchers.addMatcher('toMatch', { -1098 test: function(actual, expected) { -1099 return new RegExp(expected).test(actual); -1100 }, -1101 message: function(actual, expected) { -1102 return actual + " does not match the regular expression " + new RegExp(expected).toString(); -1103 } -1104 }); -1105 -1106 /** -1107 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -1108 * @param reg_exp -1109 */ -1110 -1111 jasmine.Matchers.addMatcher('toNotMatch', { -1112 test: function(actual, expected) { -1113 return !(new RegExp(expected).test(actual)); -1114 }, -1115 message: function(actual, expected) { -1116 return actual + " should not match " + new RegExp(expected).toString(); -1117 } -1118 }); -1119 -1120 /** -1121 * Matcher that compares the acutal to undefined. -1122 */ -1123 -1124 jasmine.Matchers.addMatcher('toBeDefined', { -1125 test: function(actual) { -1126 return (actual !== undefined); -1127 }, -1128 message: function() { -1129 return 'Expected actual to not be undefined.'; -1130 } -1131 }); -1132 -1133 /** -1134 * Matcher that compares the acutal to undefined. -1135 */ -1136 -1137 jasmine.Matchers.addMatcher('toBeUndefined', { -1138 test: function(actual) { -1139 return (actual === undefined); -1140 }, -1141 message: function(actual) { -1142 return 'Expected ' + jasmine.pp(actual) + ' to be undefined.'; -1143 } -1144 }); -1145 -1146 /** -1147 * Matcher that compares the actual to null. -1148 * -1149 */ -1150 jasmine.Matchers.addMatcher('toBeNull', { -1151 test: function(actual) { -1152 return (actual === null); -1153 }, -1154 message: function(actual) { -1155 return 'Expected ' + jasmine.pp(actual) + ' to be null.'; -1156 } -1157 }); -1158 -1159 /** -1160 * Matcher that boolean not-nots the actual. -1161 */ -1162 jasmine.Matchers.addMatcher('toBeTruthy', { -1163 test: function(actual) { -1164 return !!actual; -1165 }, -1166 message: function() { -1167 return 'Expected actual to be truthy'; -1168 } -1169 }); -1170 -1171 -1172 /** -1173 * Matcher that boolean nots the actual. -1174 */ -1175 jasmine.Matchers.addMatcher('toBeFalsy', { -1176 test: function(actual) { -1177 return !actual; -1178 }, -1179 message: function(actual) { -1180 return 'Expected ' + jasmine.pp(actual) + ' to be falsy'; -1181 } -1182 }); -1183 -1184 /** -1185 * Matcher that checks to see if the acutal, a Jasmine spy, was called. -1186 */ -1187 -1188 jasmine.Matchers.addMatcher('wasCalled', { -1189 getActual_: function() { -1190 var args = jasmine.util.argsToArray(arguments); -1191 if (args.length > 1) { -1192 throw(new Error('wasCalled does not take arguments, use wasCalledWith')); +1006 jasmine.Matchers.addMatcher = function(matcherName, options) { +1007 jasmine.Matchers.prototype[matcherName] = function () { +1008 jasmine.util.extend(this, options); +1009 var matcherArgs = jasmine.util.argsToArray(arguments); +1010 var args = [this.actual].concat(matcherArgs); +1011 var result = options.test.apply(this, args); +1012 var message; +1013 if (!result) { +1014 message = options.message.apply(this, args); +1015 } +1016 var expectationResult = new jasmine.ExpectationResult({ +1017 matcherName: matcherName, +1018 passed: result, +1019 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], +1020 actual: this.actual, +1021 message: message +1022 }); +1023 this.spec.addMatcherResult(expectationResult); +1024 return result; +1025 }; +1026 }; +1027 +1028 +1029 /** +1030 * toBe: compares the actual to the expected using === +1031 * @param expected +1032 */ +1033 +1034 jasmine.Matchers.addMatcher('toBe', { +1035 test: function (actual, expected) { +1036 return actual === expected; +1037 }, +1038 message: function(actual, expected) { +1039 return "Expected " + jasmine.pp(actual) + " to be " + jasmine.pp(expected); +1040 } +1041 }); +1042 +1043 /** +1044 * toNotBe: compares the actual to the expected using !== +1045 * @param expected +1046 */ +1047 jasmine.Matchers.addMatcher('toNotBe', { +1048 test: function (actual, expected) { +1049 return actual !== expected; +1050 }, +1051 message: function(actual, expected) { +1052 return "Expected " + jasmine.pp(actual) + " to not be " + jasmine.pp(expected); +1053 } +1054 }); +1055 +1056 /** +1057 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. +1058 * +1059 * @param expected +1060 */ +1061 +1062 jasmine.Matchers.addMatcher('toEqual', { +1063 test: function (actual, expected) { +1064 return this.env.equals_(actual, expected); +1065 }, +1066 message: function(actual, expected) { +1067 return "Expected " + jasmine.pp(actual) + " to equal " + jasmine.pp(expected); +1068 } +1069 }); +1070 +1071 /** +1072 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual +1073 * @param expected +1074 */ +1075 jasmine.Matchers.addMatcher('toNotEqual', { +1076 test: function (actual, expected) { +1077 return !this.env.equals_(actual, expected); +1078 }, +1079 message: function(actual, expected) { +1080 return "Expected " + jasmine.pp(actual) + " to not equal " + jasmine.pp(expected); +1081 } +1082 }); +1083 +1084 /** +1085 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +1086 * a pattern or a String. +1087 * +1088 * @param reg_exp +1089 */ +1090 jasmine.Matchers.addMatcher('toMatch', { +1091 test: function(actual, expected) { +1092 return new RegExp(expected).test(actual); +1093 }, +1094 message: function(actual, expected) { +1095 return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString(); +1096 } +1097 }); +1098 +1099 /** +1100 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +1101 * @param reg_exp +1102 */ +1103 +1104 jasmine.Matchers.addMatcher('toNotMatch', { +1105 test: function(actual, expected) { +1106 return !(new RegExp(expected).test(actual)); +1107 }, +1108 message: function(actual, expected) { +1109 return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString(); +1110 } +1111 }); +1112 +1113 /** +1114 * Matcher that compares the acutal to undefined. +1115 */ +1116 +1117 jasmine.Matchers.addMatcher('toBeDefined', { +1118 test: function(actual) { +1119 return (actual !== undefined); +1120 }, +1121 message: function() { +1122 return 'Expected actual to not be undefined.'; +1123 } +1124 }); +1125 +1126 /** +1127 * Matcher that compares the acutal to undefined. +1128 */ +1129 +1130 jasmine.Matchers.addMatcher('toBeUndefined', { +1131 test: function(actual) { +1132 return (actual === undefined); +1133 }, +1134 message: function(actual) { +1135 return 'Expected ' + jasmine.pp(actual) + ' to be undefined.'; +1136 } +1137 }); +1138 +1139 /** +1140 * Matcher that compares the actual to null. +1141 * +1142 */ +1143 jasmine.Matchers.addMatcher('toBeNull', { +1144 test: function(actual) { +1145 return (actual === null); +1146 }, +1147 message: function(actual) { +1148 return 'Expected ' + jasmine.pp(actual) + ' to be null.'; +1149 } +1150 }); +1151 +1152 /** +1153 * Matcher that boolean not-nots the actual. +1154 */ +1155 jasmine.Matchers.addMatcher('toBeTruthy', { +1156 test: function(actual) { +1157 return !!actual; +1158 }, +1159 message: function() { +1160 return 'Expected actual to be truthy'; +1161 } +1162 }); +1163 +1164 +1165 /** +1166 * Matcher that boolean nots the actual. +1167 */ +1168 jasmine.Matchers.addMatcher('toBeFalsy', { +1169 test: function(actual) { +1170 return !actual; +1171 }, +1172 message: function(actual) { +1173 return 'Expected ' + jasmine.pp(actual) + ' to be falsy'; +1174 } +1175 }); +1176 +1177 /** +1178 * Matcher that checks to see if the acutal, a Jasmine spy, was called. +1179 */ +1180 +1181 jasmine.Matchers.addMatcher('wasCalled', { +1182 getActual_: function() { +1183 var args = jasmine.util.argsToArray(arguments); +1184 if (args.length > 1) { +1185 throw(new Error('wasCalled does not take arguments, use wasCalledWith')); +1186 } +1187 return args.splice(0, 1)[0]; +1188 }, +1189 test: function() { +1190 var actual = this.getActual_.apply(this, arguments); +1191 if (!actual || !actual.isSpy) { +1192 return false; 1193 } -1194 return args.splice(0, 1)[0]; +1194 return actual.wasCalled; 1195 }, -1196 test: function() { +1196 message: function() { 1197 var actual = this.getActual_.apply(this, arguments); 1198 if (!actual || !actual.isSpy) { -1199 return false; +1199 return 'Actual is not a spy.'; 1200 } -1201 return actual.wasCalled; -1202 }, -1203 message: function() { -1204 var actual = this.getActual_.apply(this, arguments); -1205 if (!actual || !actual.isSpy) { -1206 return 'Actual is not a spy.'; -1207 } -1208 return "Expected spy " + actual.identity + " to have been called."; -1209 } -1210 }); -1211 -1212 /** -1213 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. -1214 */ -1215 jasmine.Matchers.addMatcher('wasNotCalled', { -1216 getActual_: function() { -1217 var args = jasmine.util.argsToArray(arguments); -1218 return args.splice(0, 1)[0]; +1201 return "Expected spy " + actual.identity + " to have been called."; +1202 } +1203 }); +1204 +1205 /** +1206 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. +1207 */ +1208 jasmine.Matchers.addMatcher('wasNotCalled', { +1209 getActual_: function() { +1210 var args = jasmine.util.argsToArray(arguments); +1211 return args.splice(0, 1)[0]; +1212 }, +1213 test: function() { +1214 var actual = this.getActual_.apply(this, arguments); +1215 if (!actual || !actual.isSpy) { +1216 return false; +1217 } +1218 return !actual.wasCalled; 1219 }, -1220 test: function() { +1220 message: function() { 1221 var actual = this.getActual_.apply(this, arguments); 1222 if (!actual || !actual.isSpy) { -1223 return false; +1223 return 'Actual is not a spy.'; 1224 } -1225 return !actual.wasCalled; -1226 }, -1227 message: function() { -1228 var actual = this.getActual_.apply(this, arguments); -1229 if (!actual || !actual.isSpy) { -1230 return 'Actual is not a spy.'; -1231 } -1232 return "Expected spy " + actual.identity + " to not have been called."; -1233 } -1234 }); -1235 -1236 jasmine.Matchers.addMatcher('wasCalledWith', { -1237 test: function() { -1238 var args = jasmine.util.argsToArray(arguments); -1239 var actual = args.splice(0, 1)[0]; -1240 if (!actual || !actual.isSpy) { -1241 return false; -1242 } -1243 return this.env.contains_(actual.argsForCall, args); -1244 }, -1245 message: function() { -1246 var args = jasmine.util.argsToArray(arguments); -1247 var actual = args.splice(0, 1)[0]; -1248 var message; -1249 if (!actual || !actual.isSpy) { -1250 message = 'Actual is not a spy'; -1251 } else { -1252 message = "Expected spy to have been called with " + jasmine.pp(args) + " but was called with " + actual.argsForCall; -1253 } -1254 return message; -1255 } -1256 }); +1225 return "Expected spy " + actual.identity + " to not have been called."; +1226 } +1227 }); +1228 +1229 jasmine.Matchers.addMatcher('wasCalledWith', { +1230 test: function() { +1231 var args = jasmine.util.argsToArray(arguments); +1232 var actual = args.splice(0, 1)[0]; +1233 if (!actual || !actual.isSpy) { +1234 return false; +1235 } +1236 return this.env.contains_(actual.argsForCall, args); +1237 }, +1238 message: function() { +1239 var args = jasmine.util.argsToArray(arguments); +1240 var actual = args.splice(0, 1)[0]; +1241 var message; +1242 if (!actual || !actual.isSpy) { +1243 message = 'Actual is not a spy'; +1244 } else { +1245 message = "Expected spy to have been called with " + jasmine.pp(args) + " but was called with " + actual.argsForCall; +1246 } +1247 return message; +1248 } +1249 }); +1250 +1251 /** +1252 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +1253 * +1254 * @example +1255 * +1256 */ 1257 1258 /** -1259 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +1259 * Matcher that checks that the expected item is an element in the actual Array. 1260 * -1261 * @example -1262 * -1263 */ -1264 -1265 /** -1266 * Matcher that checks that the expected item is an element in the actual Array. -1267 * -1268 * @param {Object} item -1269 */ -1270 -1271 jasmine.Matchers.addMatcher('toContain', { -1272 test: function(actual, expected) { -1273 return this.env.contains_(actual, expected); -1274 }, -1275 message: function(actual, expected) { -1276 return 'Expected ' + jasmine.pp(actual) + ' to contain ' + jasmine.pp(expected); -1277 } -1278 }); -1279 -1280 /** -1281 * Matcher that checks that the expected item is NOT an element in the actual Array. -1282 * -1283 * @param {Object} item -1284 */ -1285 jasmine.Matchers.addMatcher('toNotContain', { -1286 test: function(actual, expected) { -1287 return !this.env.contains_(actual, expected); -1288 }, -1289 message: function(actual, expected) { -1290 return 'Expected ' + jasmine.pp(actual) + ' to not contain ' + jasmine.pp(expected); -1291 } -1292 }); -1293 -1294 jasmine.Matchers.addMatcher('toBeLessThan', { -1295 test: function(actual, expected) { -1296 return actual < expected; -1297 }, -1298 message: function(actual, expected) { -1299 return 'Expected ' + jasmine.pp(actual) + ' to be less than ' + jasmine.pp(expected); -1300 } -1301 }); -1302 -1303 jasmine.Matchers.addMatcher('toBeGreaterThan', { -1304 test: function(actual, expected) { -1305 return actual > expected; -1306 }, -1307 message: function(actual, expected) { -1308 return 'Expected ' + jasmine.pp(actual) + ' to be greater than ' + jasmine.pp(expected); -1309 } -1310 }); -1311 -1312 /** -1313 * Matcher that checks that the expected exception was thrown by the actual. -1314 * -1315 * @param {String} expectedException -1316 */ -1317 jasmine.Matchers.addMatcher('toThrow', { -1318 getException_: function(actual, expected) { -1319 var exception; -1320 if (typeof actual != 'function') { -1321 throw new Error('Actual is not a function'); -1322 } -1323 try { -1324 actual(); -1325 } catch (e) { -1326 exception = e; -1327 } -1328 return exception; -1329 }, -1330 test: function(actual, expected) { -1331 var result = false; +1261 * @param {Object} item +1262 */ +1263 +1264 jasmine.Matchers.addMatcher('toContain', { +1265 test: function(actual, expected) { +1266 return this.env.contains_(actual, expected); +1267 }, +1268 message: function(actual, expected) { +1269 return 'Expected ' + jasmine.pp(actual) + ' to contain ' + jasmine.pp(expected); +1270 } +1271 }); +1272 +1273 /** +1274 * Matcher that checks that the expected item is NOT an element in the actual Array. +1275 * +1276 * @param {Object} item +1277 */ +1278 jasmine.Matchers.addMatcher('toNotContain', { +1279 test: function(actual, expected) { +1280 return !this.env.contains_(actual, expected); +1281 }, +1282 message: function(actual, expected) { +1283 return 'Expected ' + jasmine.pp(actual) + ' to not contain ' + jasmine.pp(expected); +1284 } +1285 }); +1286 +1287 jasmine.Matchers.addMatcher('toBeLessThan', { +1288 test: function(actual, expected) { +1289 return actual < expected; +1290 }, +1291 message: function(actual, expected) { +1292 return 'Expected ' + jasmine.pp(actual) + ' to be less than ' + jasmine.pp(expected); +1293 } +1294 }); +1295 +1296 jasmine.Matchers.addMatcher('toBeGreaterThan', { +1297 test: function(actual, expected) { +1298 return actual > expected; +1299 }, +1300 message: function(actual, expected) { +1301 return 'Expected ' + jasmine.pp(actual) + ' to be greater than ' + jasmine.pp(expected); +1302 } +1303 }); +1304 +1305 /** +1306 * Matcher that checks that the expected exception was thrown by the actual. +1307 * +1308 * @param {String} expectedException +1309 */ +1310 jasmine.Matchers.addMatcher('toThrow', { +1311 getException_: function(actual, expected) { +1312 var exception; +1313 if (typeof actual != 'function') { +1314 throw new Error('Actual is not a function'); +1315 } +1316 try { +1317 actual(); +1318 } catch (e) { +1319 exception = e; +1320 } +1321 return exception; +1322 }, +1323 test: function(actual, expected) { +1324 var result = false; +1325 var exception = this.getException_(actual, expected); +1326 if (exception) { +1327 result = (expected === undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +1328 } +1329 return result; +1330 }, +1331 message: function(actual, expected) { 1332 var exception = this.getException_(actual, expected); -1333 if (exception) { -1334 result = (expected === undefined || this.env.equals_(exception.message || exception, expected.message || expected)); -1335 } -1336 return result; -1337 }, -1338 message: function(actual, expected) { -1339 var exception = this.getException_(actual, expected); -1340 if (exception && (expected === undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -1341 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); -1342 } else { -1343 return "Expected function to throw an exception."; -1344 } -1345 } -1346 }); -1347 -1348 jasmine.Matchers.Any = function(expectedClass) { -1349 this.expectedClass = expectedClass; -1350 }; -1351 -1352 jasmine.Matchers.Any.prototype.matches = function(other) { -1353 if (this.expectedClass == String) { -1354 return typeof other == 'string' || other instanceof String; -1355 } -1356 -1357 if (this.expectedClass == Number) { -1358 return typeof other == 'number' || other instanceof Number; -1359 } -1360 -1361 if (this.expectedClass == Function) { -1362 return typeof other == 'function' || other instanceof Function; -1363 } +1333 if (exception && (expected === undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { +1334 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); +1335 } else { +1336 return "Expected function to throw an exception."; +1337 } +1338 } +1339 }); +1340 +1341 jasmine.Matchers.Any = function(expectedClass) { +1342 this.expectedClass = expectedClass; +1343 }; +1344 +1345 jasmine.Matchers.Any.prototype.matches = function(other) { +1346 if (this.expectedClass == String) { +1347 return typeof other == 'string' || other instanceof String; +1348 } +1349 +1350 if (this.expectedClass == Number) { +1351 return typeof other == 'number' || other instanceof Number; +1352 } +1353 +1354 if (this.expectedClass == Function) { +1355 return typeof other == 'function' || other instanceof Function; +1356 } +1357 +1358 if (this.expectedClass == Object) { +1359 return typeof other == 'object'; +1360 } +1361 +1362 return other instanceof this.expectedClass; +1363 }; 1364 -1365 if (this.expectedClass == Object) { -1366 return typeof other == 'object'; -1367 } +1365 jasmine.Matchers.Any.prototype.toString = function() { +1366 return '<jasmine.any(' + this.expectedClass + ')>'; +1367 }; 1368 -1369 return other instanceof this.expectedClass; -1370 }; -1371 -1372 jasmine.Matchers.Any.prototype.toString = function() { -1373 return '<jasmine.any(' + this.expectedClass + ')>'; +1369 /** +1370 * @constructor +1371 */ +1372 jasmine.MultiReporter = function() { +1373 this.subReporters_ = []; 1374 }; -1375 -1376 /** -1377 * @constructor -1378 */ -1379 jasmine.MultiReporter = function() { -1380 this.subReporters_ = []; -1381 }; -1382 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); -1383 -1384 jasmine.MultiReporter.prototype.addReporter = function(reporter) { -1385 this.subReporters_.push(reporter); -1386 }; -1387 -1388 (function() { -1389 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; -1390 for (var i = 0; i < functionNames.length; i++) { -1391 var functionName = functionNames[i]; -1392 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { -1393 return function() { -1394 for (var j = 0; j < this.subReporters_.length; j++) { -1395 var subReporter = this.subReporters_[j]; -1396 if (subReporter[functionName]) { -1397 subReporter[functionName].apply(subReporter, arguments); -1398 } -1399 } -1400 }; -1401 })(functionName); -1402 } -1403 })(); -1404 /** -1405 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults -1406 * -1407 * @constructor -1408 */ -1409 jasmine.NestedResults = function() { -1410 /** -1411 * The total count of results -1412 */ -1413 this.totalCount = 0; -1414 /** -1415 * Number of passed results -1416 */ -1417 this.passedCount = 0; -1418 /** -1419 * Number of failed results -1420 */ -1421 this.failedCount = 0; -1422 /** -1423 * Was this suite/spec skipped? -1424 */ -1425 this.skipped = false; -1426 /** -1427 * @ignore -1428 */ -1429 this.items_ = []; -1430 }; -1431 -1432 /** -1433 * Roll up the result counts. -1434 * -1435 * @param result -1436 */ -1437 jasmine.NestedResults.prototype.rollupCounts = function(result) { -1438 this.totalCount += result.totalCount; -1439 this.passedCount += result.passedCount; -1440 this.failedCount += result.failedCount; -1441 }; -1442 -1443 /** -1444 * Tracks a result's message. -1445 * @param message +1375 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); +1376 +1377 jasmine.MultiReporter.prototype.addReporter = function(reporter) { +1378 this.subReporters_.push(reporter); +1379 }; +1380 +1381 (function() { +1382 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; +1383 for (var i = 0; i < functionNames.length; i++) { +1384 var functionName = functionNames[i]; +1385 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { +1386 return function() { +1387 for (var j = 0; j < this.subReporters_.length; j++) { +1388 var subReporter = this.subReporters_[j]; +1389 if (subReporter[functionName]) { +1390 subReporter[functionName].apply(subReporter, arguments); +1391 } +1392 } +1393 }; +1394 })(functionName); +1395 } +1396 })(); +1397 /** +1398 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults +1399 * +1400 * @constructor +1401 */ +1402 jasmine.NestedResults = function() { +1403 /** +1404 * The total count of results +1405 */ +1406 this.totalCount = 0; +1407 /** +1408 * Number of passed results +1409 */ +1410 this.passedCount = 0; +1411 /** +1412 * Number of failed results +1413 */ +1414 this.failedCount = 0; +1415 /** +1416 * Was this suite/spec skipped? +1417 */ +1418 this.skipped = false; +1419 /** +1420 * @ignore +1421 */ +1422 this.items_ = []; +1423 }; +1424 +1425 /** +1426 * Roll up the result counts. +1427 * +1428 * @param result +1429 */ +1430 jasmine.NestedResults.prototype.rollupCounts = function(result) { +1431 this.totalCount += result.totalCount; +1432 this.passedCount += result.passedCount; +1433 this.failedCount += result.failedCount; +1434 }; +1435 +1436 /** +1437 * Tracks a result's message. +1438 * @param message +1439 */ +1440 jasmine.NestedResults.prototype.log = function(message) { +1441 this.items_.push(new jasmine.MessageResult(message)); +1442 }; +1443 +1444 /** +1445 * Getter for the results: message & results. 1446 */ -1447 jasmine.NestedResults.prototype.log = function(message) { -1448 this.items_.push(new jasmine.MessageResult(message)); +1447 jasmine.NestedResults.prototype.getItems = function() { +1448 return this.items_; 1449 }; 1450 1451 /** -1452 * Getter for the results: message & results. -1453 */ -1454 jasmine.NestedResults.prototype.getItems = function() { -1455 return this.items_; -1456 }; -1457 -1458 /** -1459 * Adds a result, tracking counts (total, passed, & failed) -1460 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result -1461 */ -1462 jasmine.NestedResults.prototype.addResult = function(result) { -1463 if (result.type != 'MessageResult') { -1464 if (result.items_) { -1465 this.rollupCounts(result); -1466 } else { -1467 this.totalCount++; -1468 if (result.passed()) { -1469 this.passedCount++; -1470 } else { -1471 this.failedCount++; -1472 } -1473 } -1474 } -1475 this.items_.push(result); +1452 * Adds a result, tracking counts (total, passed, & failed) +1453 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result +1454 */ +1455 jasmine.NestedResults.prototype.addResult = function(result) { +1456 if (result.type != 'MessageResult') { +1457 if (result.items_) { +1458 this.rollupCounts(result); +1459 } else { +1460 this.totalCount++; +1461 if (result.passed()) { +1462 this.passedCount++; +1463 } else { +1464 this.failedCount++; +1465 } +1466 } +1467 } +1468 this.items_.push(result); +1469 }; +1470 +1471 /** +1472 * @returns {Boolean} True if <b>everything</b> below passed +1473 */ +1474 jasmine.NestedResults.prototype.passed = function() { +1475 return this.passedCount === this.totalCount; 1476 }; -1477 -1478 /** -1479 * @returns {Boolean} True if <b>everything</b> below passed -1480 */ -1481 jasmine.NestedResults.prototype.passed = function() { -1482 return this.passedCount === this.totalCount; -1483 }; +1477 /** +1478 * Base class for pretty printing for expectation results. +1479 */ +1480 jasmine.PrettyPrinter = function() { +1481 this.ppNestLevel_ = 0; +1482 }; +1483 1484 /** -1485 * Base class for pretty printing for expectation results. -1486 */ -1487 jasmine.PrettyPrinter = function() { -1488 this.ppNestLevel_ = 0; -1489 }; -1490 -1491 /** -1492 * Formats a value in a nice, human-readable string. -1493 * -1494 * @param value -1495 * @returns {String} -1496 */ -1497 jasmine.PrettyPrinter.prototype.format = function(value) { -1498 if (this.ppNestLevel_ > 40) { -1499 // return '(jasmine.pp nested too deeply!)'; -1500 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); -1501 } -1502 -1503 this.ppNestLevel_++; -1504 try { -1505 if (value === undefined) { -1506 this.emitScalar('undefined'); -1507 } else if (value === null) { -1508 this.emitScalar('null'); -1509 } else if (value.navigator && value.frames && value.setTimeout) { -1510 this.emitScalar('<window>'); -1511 } else if (value instanceof jasmine.Matchers.Any) { -1512 this.emitScalar(value.toString()); -1513 } else if (typeof value === 'string') { -1514 this.emitString(value); -1515 } else if (typeof value === 'function') { -1516 this.emitScalar('Function'); -1517 } else if (typeof value.nodeType === 'number') { -1518 this.emitScalar('HTMLNode'); -1519 } else if (value instanceof Date) { -1520 this.emitScalar('Date(' + value + ')'); -1521 } else if (value.__Jasmine_been_here_before__) { -1522 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); -1523 } else if (jasmine.isArray_(value) || typeof value == 'object') { -1524 value.__Jasmine_been_here_before__ = true; -1525 if (jasmine.isArray_(value)) { -1526 this.emitArray(value); -1527 } else { -1528 this.emitObject(value); -1529 } -1530 delete value.__Jasmine_been_here_before__; -1531 } else { -1532 this.emitScalar(value.toString()); -1533 } -1534 } finally { -1535 this.ppNestLevel_--; +1485 * Formats a value in a nice, human-readable string. +1486 * +1487 * @param value +1488 * @returns {String} +1489 */ +1490 jasmine.PrettyPrinter.prototype.format = function(value) { +1491 if (this.ppNestLevel_ > 40) { +1492 // return '(jasmine.pp nested too deeply!)'; +1493 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); +1494 } +1495 +1496 this.ppNestLevel_++; +1497 try { +1498 if (value === undefined) { +1499 this.emitScalar('undefined'); +1500 } else if (value === null) { +1501 this.emitScalar('null'); +1502 } else if (value.navigator && value.frames && value.setTimeout) { +1503 this.emitScalar('<window>'); +1504 } else if (value instanceof jasmine.Matchers.Any) { +1505 this.emitScalar(value.toString()); +1506 } else if (typeof value === 'string') { +1507 this.emitString(value); +1508 } else if (typeof value === 'function') { +1509 this.emitScalar('Function'); +1510 } else if (typeof value.nodeType === 'number') { +1511 this.emitScalar('HTMLNode'); +1512 } else if (value instanceof Date) { +1513 this.emitScalar('Date(' + value + ')'); +1514 } else if (value.__Jasmine_been_here_before__) { +1515 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); +1516 } else if (jasmine.isArray_(value) || typeof value == 'object') { +1517 value.__Jasmine_been_here_before__ = true; +1518 if (jasmine.isArray_(value)) { +1519 this.emitArray(value); +1520 } else { +1521 this.emitObject(value); +1522 } +1523 delete value.__Jasmine_been_here_before__; +1524 } else { +1525 this.emitScalar(value.toString()); +1526 } +1527 } finally { +1528 this.ppNestLevel_--; +1529 } +1530 }; +1531 +1532 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { +1533 for (var property in obj) { +1534 if (property == '__Jasmine_been_here_before__') continue; +1535 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); 1536 } 1537 }; 1538 -1539 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { -1540 for (var property in obj) { -1541 if (property == '__Jasmine_been_here_before__') continue; -1542 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); -1543 } -1544 }; -1545 -1546 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -1547 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -1548 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -1549 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; +1539 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; +1540 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; +1541 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; +1542 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; +1543 +1544 jasmine.StringPrettyPrinter = function() { +1545 jasmine.PrettyPrinter.call(this); +1546 +1547 this.string = ''; +1548 }; +1549 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); 1550 -1551 jasmine.StringPrettyPrinter = function() { -1552 jasmine.PrettyPrinter.call(this); -1553 -1554 this.string = ''; -1555 }; -1556 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); -1557 -1558 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { -1559 this.append(value); -1560 }; -1561 -1562 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { -1563 this.append("'" + value + "'"); -1564 }; -1565 -1566 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { -1567 this.append('[ '); -1568 for (var i = 0; i < array.length; i++) { -1569 if (i > 0) { -1570 this.append(', '); -1571 } -1572 this.format(array[i]); -1573 } -1574 this.append(' ]'); -1575 }; -1576 -1577 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { -1578 var self = this; -1579 this.append('{ '); -1580 var first = true; +1551 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { +1552 this.append(value); +1553 }; +1554 +1555 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { +1556 this.append("'" + value + "'"); +1557 }; +1558 +1559 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { +1560 this.append('[ '); +1561 for (var i = 0; i < array.length; i++) { +1562 if (i > 0) { +1563 this.append(', '); +1564 } +1565 this.format(array[i]); +1566 } +1567 this.append(' ]'); +1568 }; +1569 +1570 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { +1571 var self = this; +1572 this.append('{ '); +1573 var first = true; +1574 +1575 this.iterateObject(obj, function(property, isGetter) { +1576 if (first) { +1577 first = false; +1578 } else { +1579 self.append(', '); +1580 } 1581 -1582 this.iterateObject(obj, function(property, isGetter) { -1583 if (first) { -1584 first = false; -1585 } else { -1586 self.append(', '); -1587 } -1588 -1589 self.append(property); -1590 self.append(' : '); -1591 if (isGetter) { -1592 self.append('<getter>'); -1593 } else { -1594 self.format(obj[property]); -1595 } -1596 }); -1597 -1598 this.append(' }'); -1599 }; -1600 -1601 jasmine.StringPrettyPrinter.prototype.append = function(value) { -1602 this.string += value; +1582 self.append(property); +1583 self.append(' : '); +1584 if (isGetter) { +1585 self.append('<getter>'); +1586 } else { +1587 self.format(obj[property]); +1588 } +1589 }); +1590 +1591 this.append(' }'); +1592 }; +1593 +1594 jasmine.StringPrettyPrinter.prototype.append = function(value) { +1595 this.string += value; +1596 }; +1597 jasmine.Queue = function(env) { +1598 this.env = env; +1599 this.blocks = []; +1600 this.running = false; +1601 this.index = 0; +1602 this.offset = 0; 1603 }; -1604 jasmine.Queue = function(env) { -1605 this.env = env; -1606 this.blocks = []; -1607 this.running = false; -1608 this.index = 0; -1609 this.offset = 0; -1610 }; -1611 -1612 jasmine.Queue.prototype.addBefore = function(block) { -1613 this.blocks.unshift(block); -1614 }; -1615 -1616 jasmine.Queue.prototype.add = function(block) { -1617 this.blocks.push(block); -1618 }; -1619 -1620 jasmine.Queue.prototype.insertNext = function(block) { -1621 this.blocks.splice((this.index + this.offset + 1), 0, block); -1622 this.offset++; -1623 }; -1624 -1625 jasmine.Queue.prototype.start = function(onComplete) { -1626 this.running = true; -1627 this.onComplete = onComplete; -1628 this.next_(); -1629 }; -1630 -1631 jasmine.Queue.prototype.isRunning = function() { -1632 return this.running; -1633 }; -1634 -1635 jasmine.Queue.LOOP_DONT_RECURSE = true; -1636 -1637 jasmine.Queue.prototype.next_ = function() { -1638 var self = this; -1639 var goAgain = true; +1604 +1605 jasmine.Queue.prototype.addBefore = function(block) { +1606 this.blocks.unshift(block); +1607 }; +1608 +1609 jasmine.Queue.prototype.add = function(block) { +1610 this.blocks.push(block); +1611 }; +1612 +1613 jasmine.Queue.prototype.insertNext = function(block) { +1614 this.blocks.splice((this.index + this.offset + 1), 0, block); +1615 this.offset++; +1616 }; +1617 +1618 jasmine.Queue.prototype.start = function(onComplete) { +1619 this.running = true; +1620 this.onComplete = onComplete; +1621 this.next_(); +1622 }; +1623 +1624 jasmine.Queue.prototype.isRunning = function() { +1625 return this.running; +1626 }; +1627 +1628 jasmine.Queue.LOOP_DONT_RECURSE = true; +1629 +1630 jasmine.Queue.prototype.next_ = function() { +1631 var self = this; +1632 var goAgain = true; +1633 +1634 while (goAgain) { +1635 goAgain = false; +1636 +1637 if (self.index < self.blocks.length) { +1638 var calledSynchronously = true; +1639 var completedSynchronously = false; 1640 -1641 while (goAgain) { -1642 goAgain = false; -1643 -1644 if (self.index < self.blocks.length) { -1645 var calledSynchronously = true; -1646 var completedSynchronously = false; -1647 -1648 var onComplete = function () { -1649 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { -1650 completedSynchronously = true; -1651 return; -1652 } -1653 -1654 self.offset = 0; -1655 self.index++; -1656 -1657 var now = new Date().getTime(); -1658 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { -1659 self.env.lastUpdate = now; -1660 self.env.setTimeout(function() { -1661 self.next_(); -1662 }, 0); -1663 } else { -1664 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { -1665 goAgain = true; -1666 } else { -1667 self.next_(); -1668 } -1669 } -1670 }; -1671 self.blocks[self.index].execute(onComplete); -1672 -1673 calledSynchronously = false; -1674 if (completedSynchronously) { -1675 onComplete(); -1676 } -1677 -1678 } else { -1679 self.running = false; -1680 if (self.onComplete) { -1681 self.onComplete(); -1682 } -1683 } -1684 } -1685 }; -1686 -1687 jasmine.Queue.prototype.results = function() { -1688 var results = new jasmine.NestedResults(); -1689 for (var i = 0; i < this.blocks.length; i++) { -1690 if (this.blocks[i].results) { -1691 results.addResult(this.blocks[i].results()); -1692 } -1693 } -1694 return results; -1695 }; +1641 var onComplete = function () { +1642 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { +1643 completedSynchronously = true; +1644 return; +1645 } +1646 +1647 self.offset = 0; +1648 self.index++; +1649 +1650 var now = new Date().getTime(); +1651 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { +1652 self.env.lastUpdate = now; +1653 self.env.setTimeout(function() { +1654 self.next_(); +1655 }, 0); +1656 } else { +1657 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { +1658 goAgain = true; +1659 } else { +1660 self.next_(); +1661 } +1662 } +1663 }; +1664 self.blocks[self.index].execute(onComplete); +1665 +1666 calledSynchronously = false; +1667 if (completedSynchronously) { +1668 onComplete(); +1669 } +1670 +1671 } else { +1672 self.running = false; +1673 if (self.onComplete) { +1674 self.onComplete(); +1675 } +1676 } +1677 } +1678 }; +1679 +1680 jasmine.Queue.prototype.results = function() { +1681 var results = new jasmine.NestedResults(); +1682 for (var i = 0; i < this.blocks.length; i++) { +1683 if (this.blocks[i].results) { +1684 results.addResult(this.blocks[i].results()); +1685 } +1686 } +1687 return results; +1688 }; +1689 +1690 +1691 /* JasmineReporters.reporter +1692 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to +1693 * descendants of this object to do something with the results (see json_reporter.js) +1694 */ +1695 jasmine.Reporters = {}; 1696 -1697 -1698 /* JasmineReporters.reporter -1699 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to -1700 * descendants of this object to do something with the results (see json_reporter.js) -1701 */ -1702 jasmine.Reporters = {}; -1703 -1704 jasmine.Reporters.reporter = function(callbacks) { -1705 var that = { -1706 callbacks: callbacks || {}, -1707 -1708 doCallback: function(callback, results) { -1709 if (callback) { -1710 callback(results); -1711 } +1697 jasmine.Reporters.reporter = function(callbacks) { +1698 var that = { +1699 callbacks: callbacks || {}, +1700 +1701 doCallback: function(callback, results) { +1702 if (callback) { +1703 callback(results); +1704 } +1705 }, +1706 +1707 reportRunnerResults: function(runner) { +1708 that.doCallback(that.callbacks.runnerCallback, runner); +1709 }, +1710 reportSuiteResults: function(suite) { +1711 that.doCallback(that.callbacks.suiteCallback, suite); 1712 }, -1713 -1714 reportRunnerResults: function(runner) { -1715 that.doCallback(that.callbacks.runnerCallback, runner); -1716 }, -1717 reportSuiteResults: function(suite) { -1718 that.doCallback(that.callbacks.suiteCallback, suite); -1719 }, -1720 reportSpecResults: function(spec) { -1721 that.doCallback(that.callbacks.specCallback, spec); -1722 }, -1723 log: function (str) { -1724 if (console && console.log) console.log(str); -1725 } -1726 }; -1727 -1728 return that; -1729 }; -1730 -1731 /** -1732 * Runner -1733 * -1734 * @constructor -1735 * @param {jasmine.Env} env -1736 */ -1737 jasmine.Runner = function(env) { -1738 var self = this; -1739 self.env = env; -1740 self.queue = new jasmine.Queue(env); -1741 self.before_ = []; -1742 self.after_ = []; -1743 self.suites_ = []; -1744 }; -1745 -1746 jasmine.Runner.prototype.execute = function() { -1747 var self = this; -1748 if (self.env.reporter.reportRunnerStarting) { -1749 self.env.reporter.reportRunnerStarting(this); -1750 } -1751 self.queue.start(function () { -1752 self.finishCallback(); -1753 }); -1754 }; -1755 -1756 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { -1757 beforeEachFunction.typeName = 'beforeEach'; -1758 this.before_.push(beforeEachFunction); -1759 }; -1760 -1761 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { -1762 afterEachFunction.typeName = 'afterEach'; -1763 this.after_.push(afterEachFunction); -1764 }; -1765 -1766 -1767 jasmine.Runner.prototype.finishCallback = function() { -1768 this.env.reporter.reportRunnerResults(this); -1769 }; -1770 -1771 jasmine.Runner.prototype.addSuite = function(suite) { -1772 this.suites_.push(suite); +1713 reportSpecResults: function(spec) { +1714 that.doCallback(that.callbacks.specCallback, spec); +1715 }, +1716 log: function (str) { +1717 if (console && console.log) console.log(str); +1718 } +1719 }; +1720 +1721 return that; +1722 }; +1723 +1724 /** +1725 * Runner +1726 * +1727 * @constructor +1728 * @param {jasmine.Env} env +1729 */ +1730 jasmine.Runner = function(env) { +1731 var self = this; +1732 self.env = env; +1733 self.queue = new jasmine.Queue(env); +1734 self.before_ = []; +1735 self.after_ = []; +1736 self.suites_ = []; +1737 }; +1738 +1739 jasmine.Runner.prototype.execute = function() { +1740 var self = this; +1741 if (self.env.reporter.reportRunnerStarting) { +1742 self.env.reporter.reportRunnerStarting(this); +1743 } +1744 self.queue.start(function () { +1745 self.finishCallback(); +1746 }); +1747 }; +1748 +1749 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { +1750 beforeEachFunction.typeName = 'beforeEach'; +1751 this.before_.push(beforeEachFunction); +1752 }; +1753 +1754 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { +1755 afterEachFunction.typeName = 'afterEach'; +1756 this.after_.push(afterEachFunction); +1757 }; +1758 +1759 +1760 jasmine.Runner.prototype.finishCallback = function() { +1761 this.env.reporter.reportRunnerResults(this); +1762 }; +1763 +1764 jasmine.Runner.prototype.addSuite = function(suite) { +1765 this.suites_.push(suite); +1766 }; +1767 +1768 jasmine.Runner.prototype.add = function(block) { +1769 if (block instanceof jasmine.Suite) { +1770 this.addSuite(block); +1771 } +1772 this.queue.add(block); 1773 }; 1774 -1775 jasmine.Runner.prototype.add = function(block) { -1776 if (block instanceof jasmine.Suite) { -1777 this.addSuite(block); -1778 } -1779 this.queue.add(block); -1780 }; -1781 -1782 jasmine.Runner.prototype.specs = function () { -1783 var suites = this.suites(); -1784 var specs = []; -1785 for (var i = 0; i < suites.length; i++) { -1786 specs = specs.concat(suites[i].specs()); -1787 } -1788 return specs; -1789 }; -1790 -1791 -1792 jasmine.Runner.prototype.suites = function() { -1793 return this.suites_; -1794 }; -1795 -1796 jasmine.Runner.prototype.results = function() { -1797 return this.queue.results(); -1798 }; -1799 /** -1800 * Internal representation of a Jasmine specification, or test. -1801 * -1802 * @constructor -1803 * @param {jasmine.Env} env -1804 * @param {jasmine.Suite} suite -1805 * @param {String} description -1806 */ -1807 jasmine.Spec = function(env, suite, description) { -1808 if (!env) { -1809 throw new Error('jasmine.Env() required'); -1810 } -1811 ; -1812 if (!suite) { -1813 throw new Error('jasmine.Suite() required'); -1814 } -1815 ; -1816 var spec = this; -1817 spec.id = env.nextSpecId ? env.nextSpecId() : null; -1818 spec.env = env; -1819 spec.suite = suite; -1820 spec.description = description; -1821 spec.queue = new jasmine.Queue(env); -1822 -1823 spec.afterCallbacks = []; -1824 spec.spies_ = []; -1825 -1826 spec.results_ = new jasmine.NestedResults(); -1827 spec.results_.description = description; -1828 spec.matchersClass = null; -1829 }; -1830 -1831 jasmine.Spec.prototype.getFullName = function() { -1832 return this.suite.getFullName() + ' ' + this.description + '.'; -1833 }; -1834 -1835 -1836 jasmine.Spec.prototype.results = function() { -1837 return this.results_; -1838 }; -1839 -1840 jasmine.Spec.prototype.log = function(message) { -1841 return this.results_.log(message); -1842 }; -1843 -1844 jasmine.Spec.prototype.runs = function (func) { -1845 var block = new jasmine.Block(this.env, func, this); -1846 this.addToQueue(block); -1847 return this; -1848 }; -1849 -1850 jasmine.Spec.prototype.addToQueue = function (block) { -1851 if (this.queue.isRunning()) { -1852 this.queue.insertNext(block); -1853 } else { -1854 this.queue.add(block); -1855 } -1856 }; -1857 -1858 jasmine.Spec.prototype.addMatcherResult = function(result) { -1859 this.results_.addResult(result); -1860 }; -1861 -1862 jasmine.Spec.prototype.expect = function(actual) { -1863 return new (this.getMatchersClass_())(this.env, actual, this); -1864 }; -1865 -1866 jasmine.Spec.prototype.waits = function(timeout) { -1867 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); -1868 this.addToQueue(waitsFunc); -1869 return this; -1870 }; -1871 -1872 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { -1873 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); -1874 this.addToQueue(waitsForFunc); -1875 return this; -1876 }; -1877 -1878 jasmine.Spec.prototype.fail = function (e) { -1879 var expectationResult = new jasmine.ExpectationResult({ -1880 passed: false, -1881 message: e ? jasmine.util.formatException(e) : 'Exception' -1882 }); -1883 this.results_.addResult(expectationResult); -1884 }; -1885 -1886 jasmine.Spec.prototype.getMatchersClass_ = function() { -1887 return this.matchersClass || jasmine.Matchers; -1888 }; -1889 -1890 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -1891 var parent = this.getMatchersClass_(); -1892 var newMatchersClass = function() { -1893 parent.apply(this, arguments); -1894 }; -1895 jasmine.util.inherit(newMatchersClass, parent); -1896 for (var method in matchersPrototype) { -1897 newMatchersClass.prototype[method] = matchersPrototype[method]; -1898 } -1899 this.matchersClass = newMatchersClass; -1900 }; -1901 -1902 jasmine.Spec.prototype.finishCallback = function() { -1903 this.env.reporter.reportSpecResults(this); -1904 }; -1905 -1906 jasmine.Spec.prototype.finish = function(onComplete) { -1907 this.removeAllSpies(); -1908 this.finishCallback(); -1909 if (onComplete) { -1910 onComplete(); -1911 } -1912 }; -1913 -1914 jasmine.Spec.prototype.after = function(doAfter, test) { +1775 jasmine.Runner.prototype.specs = function () { +1776 var suites = this.suites(); +1777 var specs = []; +1778 for (var i = 0; i < suites.length; i++) { +1779 specs = specs.concat(suites[i].specs()); +1780 } +1781 return specs; +1782 }; +1783 +1784 +1785 jasmine.Runner.prototype.suites = function() { +1786 return this.suites_; +1787 }; +1788 +1789 jasmine.Runner.prototype.results = function() { +1790 return this.queue.results(); +1791 }; +1792 /** +1793 * Internal representation of a Jasmine specification, or test. +1794 * +1795 * @constructor +1796 * @param {jasmine.Env} env +1797 * @param {jasmine.Suite} suite +1798 * @param {String} description +1799 */ +1800 jasmine.Spec = function(env, suite, description) { +1801 if (!env) { +1802 throw new Error('jasmine.Env() required'); +1803 } +1804 ; +1805 if (!suite) { +1806 throw new Error('jasmine.Suite() required'); +1807 } +1808 ; +1809 var spec = this; +1810 spec.id = env.nextSpecId ? env.nextSpecId() : null; +1811 spec.env = env; +1812 spec.suite = suite; +1813 spec.description = description; +1814 spec.queue = new jasmine.Queue(env); +1815 +1816 spec.afterCallbacks = []; +1817 spec.spies_ = []; +1818 +1819 spec.results_ = new jasmine.NestedResults(); +1820 spec.results_.description = description; +1821 spec.matchersClass = null; +1822 }; +1823 +1824 jasmine.Spec.prototype.getFullName = function() { +1825 return this.suite.getFullName() + ' ' + this.description + '.'; +1826 }; +1827 +1828 +1829 jasmine.Spec.prototype.results = function() { +1830 return this.results_; +1831 }; +1832 +1833 jasmine.Spec.prototype.log = function(message) { +1834 return this.results_.log(message); +1835 }; +1836 +1837 jasmine.Spec.prototype.runs = function (func) { +1838 var block = new jasmine.Block(this.env, func, this); +1839 this.addToQueue(block); +1840 return this; +1841 }; +1842 +1843 jasmine.Spec.prototype.addToQueue = function (block) { +1844 if (this.queue.isRunning()) { +1845 this.queue.insertNext(block); +1846 } else { +1847 this.queue.add(block); +1848 } +1849 }; +1850 +1851 jasmine.Spec.prototype.addMatcherResult = function(result) { +1852 this.results_.addResult(result); +1853 }; +1854 +1855 jasmine.Spec.prototype.expect = function(actual) { +1856 return new (this.getMatchersClass_())(this.env, actual, this); +1857 }; +1858 +1859 jasmine.Spec.prototype.waits = function(timeout) { +1860 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); +1861 this.addToQueue(waitsFunc); +1862 return this; +1863 }; +1864 +1865 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { +1866 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); +1867 this.addToQueue(waitsForFunc); +1868 return this; +1869 }; +1870 +1871 jasmine.Spec.prototype.fail = function (e) { +1872 var expectationResult = new jasmine.ExpectationResult({ +1873 passed: false, +1874 message: e ? jasmine.util.formatException(e) : 'Exception' +1875 }); +1876 this.results_.addResult(expectationResult); +1877 }; +1878 +1879 jasmine.Spec.prototype.getMatchersClass_ = function() { +1880 return this.matchersClass || jasmine.Matchers; +1881 }; +1882 +1883 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +1884 var parent = this.getMatchersClass_(); +1885 var newMatchersClass = function() { +1886 parent.apply(this, arguments); +1887 }; +1888 jasmine.util.inherit(newMatchersClass, parent); +1889 for (var method in matchersPrototype) { +1890 newMatchersClass.prototype[method] = matchersPrototype[method]; +1891 } +1892 this.matchersClass = newMatchersClass; +1893 }; +1894 +1895 jasmine.Spec.prototype.finishCallback = function() { +1896 this.env.reporter.reportSpecResults(this); +1897 }; +1898 +1899 jasmine.Spec.prototype.finish = function(onComplete) { +1900 this.removeAllSpies(); +1901 this.finishCallback(); +1902 if (onComplete) { +1903 onComplete(); +1904 } +1905 }; +1906 +1907 jasmine.Spec.prototype.after = function(doAfter, test) { +1908 +1909 if (this.queue.isRunning()) { +1910 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +1911 } else { +1912 this.afterCallbacks.unshift(doAfter); +1913 } +1914 }; 1915 -1916 if (this.queue.isRunning()) { -1917 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -1918 } else { -1919 this.afterCallbacks.unshift(doAfter); -1920 } -1921 }; -1922 -1923 jasmine.Spec.prototype.execute = function(onComplete) { -1924 var spec = this; -1925 if (!spec.env.specFilter(spec)) { -1926 spec.results_.skipped = true; -1927 spec.finish(onComplete); -1928 return; -1929 } -1930 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); -1931 -1932 spec.env.currentSpec = spec; +1916 jasmine.Spec.prototype.execute = function(onComplete) { +1917 var spec = this; +1918 if (!spec.env.specFilter(spec)) { +1919 spec.results_.skipped = true; +1920 spec.finish(onComplete); +1921 return; +1922 } +1923 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +1924 +1925 spec.env.currentSpec = spec; +1926 +1927 spec.addBeforesAndAftersToQueue(); +1928 +1929 spec.queue.start(function () { +1930 spec.finish(onComplete); +1931 }); +1932 }; 1933 -1934 spec.addBeforesAndAftersToQueue(); -1935 -1936 spec.queue.start(function () { -1937 spec.finish(onComplete); -1938 }); -1939 }; -1940 -1941 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -1942 var runner = this.env.currentRunner(); -1943 for (var suite = this.suite; suite; suite = suite.parentSuite) { -1944 for (var i = 0; i < suite.before_.length; i++) { -1945 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -1946 } -1947 } -1948 for (var i = 0; i < runner.before_.length; i++) { -1949 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -1950 } -1951 for (i = 0; i < this.afterCallbacks.length; i++) { -1952 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -1953 } -1954 for (suite = this.suite; suite; suite = suite.parentSuite) { -1955 for (var i = 0; i < suite.after_.length; i++) { -1956 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -1957 } -1958 } -1959 for (var i = 0; i < runner.after_.length; i++) { -1960 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -1961 } -1962 }; -1963 -1964 jasmine.Spec.prototype.explodes = function() { -1965 throw 'explodes function should not have been called'; -1966 }; -1967 -1968 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -1969 if (obj == undefined) { -1970 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -1971 } -1972 -1973 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -1974 throw methodName + '() method does not exist'; -1975 } -1976 -1977 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -1978 throw new Error(methodName + ' has already been spied upon'); -1979 } +1934 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +1935 var runner = this.env.currentRunner(); +1936 for (var suite = this.suite; suite; suite = suite.parentSuite) { +1937 for (var i = 0; i < suite.before_.length; i++) { +1938 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +1939 } +1940 } +1941 for (var i = 0; i < runner.before_.length; i++) { +1942 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +1943 } +1944 for (i = 0; i < this.afterCallbacks.length; i++) { +1945 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +1946 } +1947 for (suite = this.suite; suite; suite = suite.parentSuite) { +1948 for (var i = 0; i < suite.after_.length; i++) { +1949 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +1950 } +1951 } +1952 for (var i = 0; i < runner.after_.length; i++) { +1953 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +1954 } +1955 }; +1956 +1957 jasmine.Spec.prototype.explodes = function() { +1958 throw 'explodes function should not have been called'; +1959 }; +1960 +1961 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +1962 if (obj == undefined) { +1963 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1964 } +1965 +1966 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { +1967 throw methodName + '() method does not exist'; +1968 } +1969 +1970 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +1971 throw new Error(methodName + ' has already been spied upon'); +1972 } +1973 +1974 var spyObj = jasmine.createSpy(methodName); +1975 +1976 this.spies_.push(spyObj); +1977 spyObj.baseObj = obj; +1978 spyObj.methodName = methodName; +1979 spyObj.originalValue = obj[methodName]; 1980 -1981 var spyObj = jasmine.createSpy(methodName); +1981 obj[methodName] = spyObj; 1982 -1983 this.spies_.push(spyObj); -1984 spyObj.baseObj = obj; -1985 spyObj.methodName = methodName; -1986 spyObj.originalValue = obj[methodName]; -1987 -1988 obj[methodName] = spyObj; -1989 -1990 return spyObj; -1991 }; -1992 -1993 jasmine.Spec.prototype.removeAllSpies = function() { -1994 for (var i = 0; i < this.spies_.length; i++) { -1995 var spy = this.spies_[i]; -1996 spy.baseObj[spy.methodName] = spy.originalValue; -1997 } -1998 this.spies_ = []; -1999 }; -2000 -2001 /** -2002 * Internal representation of a Jasmine suite. -2003 * -2004 * @constructor -2005 * @param {jasmine.Env} env -2006 * @param {String} description -2007 * @param {Function} specDefinitions -2008 * @param {jasmine.Suite} parentSuite -2009 */ -2010 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { -2011 var self = this; -2012 self.id = env.nextSuiteId ? env.nextSuiteId() : null; -2013 self.description = description; -2014 self.queue = new jasmine.Queue(env); -2015 self.parentSuite = parentSuite; -2016 self.env = env; -2017 self.before_ = []; -2018 self.after_ = []; -2019 self.specs_ = []; -2020 }; -2021 -2022 jasmine.Suite.prototype.getFullName = function() { -2023 var fullName = this.description; -2024 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { -2025 fullName = parentSuite.description + ' ' + fullName; -2026 } -2027 return fullName; -2028 }; -2029 -2030 jasmine.Suite.prototype.finish = function(onComplete) { -2031 this.env.reporter.reportSuiteResults(this); -2032 this.finished = true; -2033 if (typeof(onComplete) == 'function') { -2034 onComplete(); -2035 } -2036 }; -2037 -2038 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { -2039 beforeEachFunction.typeName = 'beforeEach'; -2040 this.before_.push(beforeEachFunction); -2041 }; -2042 -2043 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { -2044 afterEachFunction.typeName = 'afterEach'; -2045 this.after_.push(afterEachFunction); -2046 }; -2047 -2048 jasmine.Suite.prototype.results = function() { -2049 return this.queue.results(); -2050 }; -2051 -2052 jasmine.Suite.prototype.add = function(block) { -2053 if (block instanceof jasmine.Suite) { -2054 this.env.currentRunner().addSuite(block); -2055 } else { -2056 this.specs_.push(block); -2057 } -2058 this.queue.add(block); -2059 }; -2060 -2061 jasmine.Suite.prototype.specs = function() { -2062 return this.specs_; +1983 return spyObj; +1984 }; +1985 +1986 jasmine.Spec.prototype.removeAllSpies = function() { +1987 for (var i = 0; i < this.spies_.length; i++) { +1988 var spy = this.spies_[i]; +1989 spy.baseObj[spy.methodName] = spy.originalValue; +1990 } +1991 this.spies_ = []; +1992 }; +1993 +1994 /** +1995 * Internal representation of a Jasmine suite. +1996 * +1997 * @constructor +1998 * @param {jasmine.Env} env +1999 * @param {String} description +2000 * @param {Function} specDefinitions +2001 * @param {jasmine.Suite} parentSuite +2002 */ +2003 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { +2004 var self = this; +2005 self.id = env.nextSuiteId ? env.nextSuiteId() : null; +2006 self.description = description; +2007 self.queue = new jasmine.Queue(env); +2008 self.parentSuite = parentSuite; +2009 self.env = env; +2010 self.before_ = []; +2011 self.after_ = []; +2012 self.specs_ = []; +2013 }; +2014 +2015 jasmine.Suite.prototype.getFullName = function() { +2016 var fullName = this.description; +2017 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { +2018 fullName = parentSuite.description + ' ' + fullName; +2019 } +2020 return fullName; +2021 }; +2022 +2023 jasmine.Suite.prototype.finish = function(onComplete) { +2024 this.env.reporter.reportSuiteResults(this); +2025 this.finished = true; +2026 if (typeof(onComplete) == 'function') { +2027 onComplete(); +2028 } +2029 }; +2030 +2031 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { +2032 beforeEachFunction.typeName = 'beforeEach'; +2033 this.before_.push(beforeEachFunction); +2034 }; +2035 +2036 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { +2037 afterEachFunction.typeName = 'afterEach'; +2038 this.after_.push(afterEachFunction); +2039 }; +2040 +2041 jasmine.Suite.prototype.results = function() { +2042 return this.queue.results(); +2043 }; +2044 +2045 jasmine.Suite.prototype.add = function(block) { +2046 if (block instanceof jasmine.Suite) { +2047 this.env.currentRunner().addSuite(block); +2048 } else { +2049 this.specs_.push(block); +2050 } +2051 this.queue.add(block); +2052 }; +2053 +2054 jasmine.Suite.prototype.specs = function() { +2055 return this.specs_; +2056 }; +2057 +2058 jasmine.Suite.prototype.execute = function(onComplete) { +2059 var self = this; +2060 this.queue.start(function () { +2061 self.finish(onComplete); +2062 }); 2063 }; -2064 -2065 jasmine.Suite.prototype.execute = function(onComplete) { -2066 var self = this; -2067 this.queue.start(function () { -2068 self.finish(onComplete); -2069 }); -2070 }; -2071 jasmine.WaitsBlock = function(env, timeout, spec) { -2072 this.timeout = timeout; -2073 jasmine.Block.call(this, env, null, spec); -2074 }; -2075 -2076 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); -2077 -2078 jasmine.WaitsBlock.prototype.execute = function (onComplete) { -2079 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); -2080 this.env.setTimeout(function () { -2081 onComplete(); -2082 }, this.timeout); +2064 jasmine.WaitsBlock = function(env, timeout, spec) { +2065 this.timeout = timeout; +2066 jasmine.Block.call(this, env, null, spec); +2067 }; +2068 +2069 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); +2070 +2071 jasmine.WaitsBlock.prototype.execute = function (onComplete) { +2072 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); +2073 this.env.setTimeout(function () { +2074 onComplete(); +2075 }, this.timeout); +2076 }; +2077 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { +2078 this.timeout = timeout; +2079 this.latchFunction = latchFunction; +2080 this.message = message; +2081 this.totalTimeSpentWaitingForLatch = 0; +2082 jasmine.Block.call(this, env, null, spec); 2083 }; -2084 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { -2085 this.timeout = timeout; -2086 this.latchFunction = latchFunction; -2087 this.message = message; -2088 this.totalTimeSpentWaitingForLatch = 0; -2089 jasmine.Block.call(this, env, null, spec); -2090 }; -2091 -2092 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); -2093 -2094 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; -2095 -2096 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { -2097 var self = this; -2098 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); -2099 var latchFunctionResult; -2100 try { -2101 latchFunctionResult = self.latchFunction.apply(self.spec); -2102 } catch (e) { -2103 self.spec.fail(e); -2104 onComplete(); -2105 return; -2106 } -2107 -2108 if (latchFunctionResult) { -2109 onComplete(); -2110 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { -2111 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); -2112 self.spec.fail({ -2113 name: 'timeout', -2114 message: message -2115 }); -2116 self.spec._next(); -2117 } else { -2118 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; -2119 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); -2120 } -2121 }; -2122 // Mock setTimeout, clearTimeout -2123 // Contributed by Pivotal Computer Systems, www.pivotalsf.com -2124 -2125 jasmine.FakeTimer = function() { -2126 this.reset(); +2084 +2085 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +2086 +2087 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +2088 +2089 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { +2090 var self = this; +2091 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); +2092 var latchFunctionResult; +2093 try { +2094 latchFunctionResult = self.latchFunction.apply(self.spec); +2095 } catch (e) { +2096 self.spec.fail(e); +2097 onComplete(); +2098 return; +2099 } +2100 +2101 if (latchFunctionResult) { +2102 onComplete(); +2103 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { +2104 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); +2105 self.spec.fail({ +2106 name: 'timeout', +2107 message: message +2108 }); +2109 self.spec._next(); +2110 } else { +2111 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; +2112 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); +2113 } +2114 }; +2115 // Mock setTimeout, clearTimeout +2116 // Contributed by Pivotal Computer Systems, www.pivotalsf.com +2117 +2118 jasmine.FakeTimer = function() { +2119 this.reset(); +2120 +2121 var self = this; +2122 self.setTimeout = function(funcToCall, millis) { +2123 self.timeoutsMade++; +2124 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); +2125 return self.timeoutsMade; +2126 }; 2127 -2128 var self = this; -2129 self.setTimeout = function(funcToCall, millis) { -2130 self.timeoutsMade++; -2131 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); -2132 return self.timeoutsMade; -2133 }; -2134 -2135 self.setInterval = function(funcToCall, millis) { -2136 self.timeoutsMade++; -2137 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); -2138 return self.timeoutsMade; -2139 }; -2140 -2141 self.clearTimeout = function(timeoutKey) { -2142 self.scheduledFunctions[timeoutKey] = undefined; -2143 }; -2144 -2145 self.clearInterval = function(timeoutKey) { -2146 self.scheduledFunctions[timeoutKey] = undefined; -2147 }; -2148 -2149 }; -2150 -2151 jasmine.FakeTimer.prototype.reset = function() { -2152 this.timeoutsMade = 0; -2153 this.scheduledFunctions = {}; -2154 this.nowMillis = 0; +2128 self.setInterval = function(funcToCall, millis) { +2129 self.timeoutsMade++; +2130 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); +2131 return self.timeoutsMade; +2132 }; +2133 +2134 self.clearTimeout = function(timeoutKey) { +2135 self.scheduledFunctions[timeoutKey] = undefined; +2136 }; +2137 +2138 self.clearInterval = function(timeoutKey) { +2139 self.scheduledFunctions[timeoutKey] = undefined; +2140 }; +2141 +2142 }; +2143 +2144 jasmine.FakeTimer.prototype.reset = function() { +2145 this.timeoutsMade = 0; +2146 this.scheduledFunctions = {}; +2147 this.nowMillis = 0; +2148 }; +2149 +2150 jasmine.FakeTimer.prototype.tick = function(millis) { +2151 var oldMillis = this.nowMillis; +2152 var newMillis = oldMillis + millis; +2153 this.runFunctionsWithinRange(oldMillis, newMillis); +2154 this.nowMillis = newMillis; 2155 }; 2156 -2157 jasmine.FakeTimer.prototype.tick = function(millis) { -2158 var oldMillis = this.nowMillis; -2159 var newMillis = oldMillis + millis; -2160 this.runFunctionsWithinRange(oldMillis, newMillis); -2161 this.nowMillis = newMillis; -2162 }; -2163 -2164 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { -2165 var scheduledFunc; -2166 var funcsToRun = []; -2167 for (var timeoutKey in this.scheduledFunctions) { -2168 scheduledFunc = this.scheduledFunctions[timeoutKey]; -2169 if (scheduledFunc != undefined && -2170 scheduledFunc.runAtMillis >= oldMillis && -2171 scheduledFunc.runAtMillis <= nowMillis) { -2172 funcsToRun.push(scheduledFunc); -2173 this.scheduledFunctions[timeoutKey] = undefined; -2174 } -2175 } -2176 -2177 if (funcsToRun.length > 0) { -2178 funcsToRun.sort(function(a, b) { -2179 return a.runAtMillis - b.runAtMillis; -2180 }); -2181 for (var i = 0; i < funcsToRun.length; ++i) { -2182 try { -2183 var funcToRun = funcsToRun[i]; -2184 this.nowMillis = funcToRun.runAtMillis; -2185 funcToRun.funcToCall(); -2186 if (funcToRun.recurring) { -2187 this.scheduleFunction(funcToRun.timeoutKey, -2188 funcToRun.funcToCall, -2189 funcToRun.millis, -2190 true); -2191 } -2192 } catch(e) { -2193 } -2194 } -2195 this.runFunctionsWithinRange(oldMillis, nowMillis); -2196 } -2197 }; -2198 -2199 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { -2200 this.scheduledFunctions[timeoutKey] = { -2201 runAtMillis: this.nowMillis + millis, -2202 funcToCall: funcToCall, -2203 recurring: recurring, -2204 timeoutKey: timeoutKey, -2205 millis: millis -2206 }; -2207 }; -2208 -2209 -2210 jasmine.Clock = { -2211 defaultFakeTimer: new jasmine.FakeTimer(), -2212 -2213 reset: function() { -2214 jasmine.Clock.assertInstalled(); -2215 jasmine.Clock.defaultFakeTimer.reset(); -2216 }, -2217 -2218 tick: function(millis) { -2219 jasmine.Clock.assertInstalled(); -2220 jasmine.Clock.defaultFakeTimer.tick(millis); -2221 }, -2222 -2223 runFunctionsWithinRange: function(oldMillis, nowMillis) { -2224 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); -2225 }, -2226 -2227 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { -2228 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); +2157 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { +2158 var scheduledFunc; +2159 var funcsToRun = []; +2160 for (var timeoutKey in this.scheduledFunctions) { +2161 scheduledFunc = this.scheduledFunctions[timeoutKey]; +2162 if (scheduledFunc != undefined && +2163 scheduledFunc.runAtMillis >= oldMillis && +2164 scheduledFunc.runAtMillis <= nowMillis) { +2165 funcsToRun.push(scheduledFunc); +2166 this.scheduledFunctions[timeoutKey] = undefined; +2167 } +2168 } +2169 +2170 if (funcsToRun.length > 0) { +2171 funcsToRun.sort(function(a, b) { +2172 return a.runAtMillis - b.runAtMillis; +2173 }); +2174 for (var i = 0; i < funcsToRun.length; ++i) { +2175 try { +2176 var funcToRun = funcsToRun[i]; +2177 this.nowMillis = funcToRun.runAtMillis; +2178 funcToRun.funcToCall(); +2179 if (funcToRun.recurring) { +2180 this.scheduleFunction(funcToRun.timeoutKey, +2181 funcToRun.funcToCall, +2182 funcToRun.millis, +2183 true); +2184 } +2185 } catch(e) { +2186 } +2187 } +2188 this.runFunctionsWithinRange(oldMillis, nowMillis); +2189 } +2190 }; +2191 +2192 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { +2193 this.scheduledFunctions[timeoutKey] = { +2194 runAtMillis: this.nowMillis + millis, +2195 funcToCall: funcToCall, +2196 recurring: recurring, +2197 timeoutKey: timeoutKey, +2198 millis: millis +2199 }; +2200 }; +2201 +2202 +2203 jasmine.Clock = { +2204 defaultFakeTimer: new jasmine.FakeTimer(), +2205 +2206 reset: function() { +2207 jasmine.Clock.assertInstalled(); +2208 jasmine.Clock.defaultFakeTimer.reset(); +2209 }, +2210 +2211 tick: function(millis) { +2212 jasmine.Clock.assertInstalled(); +2213 jasmine.Clock.defaultFakeTimer.tick(millis); +2214 }, +2215 +2216 runFunctionsWithinRange: function(oldMillis, nowMillis) { +2217 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); +2218 }, +2219 +2220 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { +2221 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); +2222 }, +2223 +2224 useMock: function() { +2225 var spec = jasmine.getEnv().currentSpec; +2226 spec.after(jasmine.Clock.uninstallMock); +2227 +2228 jasmine.Clock.installMock(); 2229 }, 2230 -2231 useMock: function() { -2232 var spec = jasmine.getEnv().currentSpec; -2233 spec.after(jasmine.Clock.uninstallMock); +2231 installMock: function() { +2232 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; +2233 }, 2234 -2235 jasmine.Clock.installMock(); -2236 }, -2237 -2238 installMock: function() { -2239 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; -2240 }, -2241 -2242 uninstallMock: function() { -2243 jasmine.Clock.assertInstalled(); -2244 jasmine.Clock.installed = jasmine.Clock.real; +2235 uninstallMock: function() { +2236 jasmine.Clock.assertInstalled(); +2237 jasmine.Clock.installed = jasmine.Clock.real; +2238 }, +2239 +2240 real: { +2241 setTimeout: window.setTimeout, +2242 clearTimeout: window.clearTimeout, +2243 setInterval: window.setInterval, +2244 clearInterval: window.clearInterval 2245 }, 2246 -2247 real: { -2248 setTimeout: window.setTimeout, -2249 clearTimeout: window.clearTimeout, -2250 setInterval: window.setInterval, -2251 clearInterval: window.clearInterval -2252 }, -2253 -2254 assertInstalled: function() { -2255 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { -2256 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -2257 } -2258 }, -2259 -2260 installed: null -2261 }; -2262 jasmine.Clock.installed = jasmine.Clock.real; -2263 -2264 //else for IE support -2265 window.setTimeout = function(funcToCall, millis) { -2266 if (jasmine.Clock.installed.setTimeout.apply) { -2267 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -2268 } else { -2269 return jasmine.Clock.installed.setTimeout(funcToCall, millis); -2270 } -2271 }; -2272 -2273 window.setInterval = function(funcToCall, millis) { -2274 if (jasmine.Clock.installed.setInterval.apply) { -2275 return jasmine.Clock.installed.setInterval.apply(this, arguments); -2276 } else { -2277 return jasmine.Clock.installed.setInterval(funcToCall, millis); -2278 } -2279 }; -2280 -2281 window.clearTimeout = function(timeoutKey) { -2282 if (jasmine.Clock.installed.clearTimeout.apply) { -2283 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -2284 } else { -2285 return jasmine.Clock.installed.clearTimeout(timeoutKey); -2286 } -2287 }; -2288 -2289 window.clearInterval = function(timeoutKey) { -2290 if (jasmine.Clock.installed.clearTimeout.apply) { -2291 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -2292 } else { -2293 return jasmine.Clock.installed.clearInterval(timeoutKey); -2294 } -2295 }; -2296 -2297 \ No newline at end of file +2247 assertInstalled: function() { +2248 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { +2249 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); +2250 } +2251 }, +2252 +2253 installed: null +2254 }; +2255 jasmine.Clock.installed = jasmine.Clock.real; +2256 +2257 //else for IE support +2258 window.setTimeout = function(funcToCall, millis) { +2259 if (jasmine.Clock.installed.setTimeout.apply) { +2260 return jasmine.Clock.installed.setTimeout.apply(this, arguments); +2261 } else { +2262 return jasmine.Clock.installed.setTimeout(funcToCall, millis); +2263 } +2264 }; +2265 +2266 window.setInterval = function(funcToCall, millis) { +2267 if (jasmine.Clock.installed.setInterval.apply) { +2268 return jasmine.Clock.installed.setInterval.apply(this, arguments); +2269 } else { +2270 return jasmine.Clock.installed.setInterval(funcToCall, millis); +2271 } +2272 }; +2273 +2274 window.clearTimeout = function(timeoutKey) { +2275 if (jasmine.Clock.installed.clearTimeout.apply) { +2276 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +2277 } else { +2278 return jasmine.Clock.installed.clearTimeout(timeoutKey); +2279 } +2280 }; +2281 +2282 window.clearInterval = function(timeoutKey) { +2283 if (jasmine.Clock.installed.clearTimeout.apply) { +2284 return jasmine.Clock.installed.clearInterval.apply(this, arguments); +2285 } else { +2286 return jasmine.Clock.installed.clearInterval(timeoutKey); +2287 } +2288 }; +2289 +2290 \ No newline at end of file diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index f054ae7d..9a625a5a 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -536,7 +536,7 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1256870877 + "revision": 1256873610 }; /** * @namespace @@ -1003,18 +1003,11 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) { return result; }; -/** - * Matcher that compares the actual to the expected using ===. - * - * @param expected - */ - - jasmine.Matchers.addMatcher = function(matcherName, options) { jasmine.Matchers.prototype[matcherName] = function () { jasmine.util.extend(this, options); - var expected = jasmine.util.argsToArray(arguments); - var args = [this.actual].concat(expected); + var matcherArgs = jasmine.util.argsToArray(arguments); + var args = [this.actual].concat(matcherArgs); var result = options.test.apply(this, args); var message; if (!result) { @@ -1023,7 +1016,7 @@ jasmine.Matchers.addMatcher = function(matcherName, options) { var expectationResult = new jasmine.ExpectationResult({ matcherName: matcherName, passed: result, - expected: expected, + expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], actual: this.actual, message: message }); @@ -1099,7 +1092,7 @@ jasmine.Matchers.addMatcher('toMatch', { return new RegExp(expected).test(actual); }, message: function(actual, expected) { - return actual + " does not match the regular expression " + new RegExp(expected).toString(); + return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString(); } }); @@ -1113,7 +1106,7 @@ jasmine.Matchers.addMatcher('toNotMatch', { return !(new RegExp(expected).test(actual)); }, message: function(actual, expected) { - return actual + " should not match " + new RegExp(expected).toString(); + return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString(); } }); diff --git a/spec/suites/MatchersSpec.js b/spec/suites/MatchersSpec.js index f7bae7f8..156bc3bd 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -48,31 +48,34 @@ describe("jasmine.Matchers", function() { }); it("toEqual to build an Expectation Result", function() { - var matcher = match('a'); - matcher.toEqual('b'); + var actual = 'a'; + var matcher = match(actual); + var expected = 'b'; + matcher.toEqual(expected); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; expect(result.matcherName).toEqual("toEqual"); expect(result.passed()).toEqual(false); - expect(result.message).toMatch("a"); - expect(result.message).toMatch("b"); - expect(result.expected).toEqual(["b"]); - expect(result.actual).toEqual("a"); + expect(result.message).toMatch(jasmine.pp(actual)); + expect(result.message).toMatch(jasmine.pp(expected)); + expect(result.expected).toEqual(expected); + expect(result.actual).toEqual(actual); }); it("toNotEqual to build an Expectation Result", function() { - var matcher = match('a'); - matcher.toNotEqual('a'); + var str = 'a'; + var matcher = match(str); + matcher.toNotEqual(str); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; expect(result.matcherName).toEqual("toNotEqual"); expect(result.passed()).toEqual(false); - expect(result.message).toMatch(/a/); - expect(result.message).toMatch(/not/); - expect(result.expected).toEqual(["a"]); - expect(result.actual).toEqual("a"); + expect(result.message).toMatch(jasmine.pp(str)); + expect(result.message).toMatch('not'); + expect(result.expected).toEqual(str); + expect(result.actual).toEqual(str); }); it('toBe should return true only if the expected and actual items === each other', function() { @@ -100,7 +103,7 @@ describe("jasmine.Matchers", function() { expect(result.passed()).toEqual(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch(jasmine.pp(expected)); - expect(result.expected).toEqual([expected]); + expect(result.expected).toEqual(expected); expect(result.actual).toEqual(actual); }); @@ -114,7 +117,7 @@ describe("jasmine.Matchers", function() { expect(result.matcherName).toEqual("toNotBe"); expect(result.passed()).toEqual(false); expect(result.message).toMatch(str); - expect(result.expected).toEqual([str]); + expect(result.expected).toEqual(str); expect(result.actual).toEqual(str); }); @@ -133,57 +136,68 @@ describe("jasmine.Matchers", function() { }); it("toMatch w/ RegExp to build an ExpectationResult", function() { - var matcher = match('a'); - matcher.toMatch(/b/); + var actual = 'a'; + var matcher = match(actual); + var expected = /b/; + matcher.toMatch(expected); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; expect(result.matcherName).toEqual("toMatch"); expect(result.passed()).toEqual(false); - expect(result.message).toEqual("a does not match the regular expression /b/"); - expect(result.expected.toString()).toEqual("/b/"); - expect(result.actual).toEqual("a"); + expect(result.message).toMatch(jasmine.pp(actual)); + expect(result.message).toMatch(expected.toString()); + expect(result.expected).toEqual(expected); + expect(result.actual).toEqual(actual); }); it("toMatch w/ String to build an ExpectationResult", function() { - var matcher = match('a'); - matcher.toMatch("b"); + var actual = 'a'; + var matcher = match(actual); + var expected = 'b'; + matcher.toMatch(expected); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; expect(result.matcherName).toEqual("toMatch"); expect(result.passed()).toEqual(false); - expect(result.message).toEqual("a does not match the regular expression /b/"); - expect(result.expected.toString()).toEqual("b"); - expect(result.actual).toEqual("a"); + expect(result.message).toMatch(jasmine.pp(actual)); + expect(result.message).toMatch(new RegExp(expected).toString()); + expect(result.expected).toEqual(expected); + expect(result.actual).toEqual(actual); }); it("toNotMatch w/ RegExp to build an ExpectationResult", function() { - var matcher = match('a'); - matcher.toNotMatch(/a/); + var actual = 'a'; + var matcher = match(actual); + var expected = /a/; + matcher.toNotMatch(expected); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; expect(result.matcherName).toEqual("toNotMatch"); expect(result.passed()).toEqual(false); - expect(result.message).toMatch("/a/"); + expect(result.message).toMatch(expected.toString()); + expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch("not"); - expect(result.expected.toString()).toEqual("/a/"); - expect(result.actual).toEqual("a"); + expect(result.expected).toEqual(expected); + expect(result.actual).toEqual(actual); }); it("toNotMatch w/ String to build an ExpectationResult", function() { - var matcher = match('a'); - matcher.toNotMatch('a'); + var str = 'a'; + var matcher = match(str); + matcher.toNotMatch(str); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; expect(result.matcherName).toEqual("toNotMatch"); expect(result.passed()).toEqual(false); - expect(result.message).toMatch("/a/"); + expect(result.message).toMatch(jasmine.pp(str)); + expect(result.message).toMatch(new RegExp(str).toString()); expect(result.message).toMatch("not"); - expect(result.expected.toString()).toEqual('a'); - expect(result.actual).toEqual("a"); + expect(result.expected).toEqual(str); + expect(result.actual).toEqual(str); }); it("toBeDefined", function() { @@ -361,7 +375,7 @@ describe("jasmine.Matchers", function() { expect(result.message).toMatch('contain'); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.actual).toEqual(actual); - expect(result.expected).toEqual([expected]); + expect(result.expected).toEqual(expected); }); it("toNotContain to build an ExpectationResult", function() { @@ -378,7 +392,7 @@ describe("jasmine.Matchers", function() { expect(result.message).toMatch('not contain'); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.actual).toEqual(actual); - expect(result.expected).toEqual([expected]); + expect(result.expected).toEqual(expected); }); it("toBeLessThan should pass if actual is less than expected", function() { @@ -400,7 +414,7 @@ describe("jasmine.Matchers", function() { expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than'); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.actual).toEqual(actual); - expect(result.expected).toEqual([expected]); + expect(result.expected).toEqual(expected); }); it("toBeGreaterThan should pass if actual is greater than expected", function() { @@ -422,7 +436,7 @@ describe("jasmine.Matchers", function() { expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than'); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.actual).toEqual(actual); - expect(result.expected).toEqual([expected]); + expect(result.expected).toEqual(expected); }); it("toThrow", function() { @@ -443,12 +457,13 @@ describe("jasmine.Matchers", function() { var exception; try { - (function (){ - new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow(); - })(); + (function () { + new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow(); + })(); } catch (e) { exception = e; - }; + } + ; expect(exception).toBeDefined(); expect(exception.message).toEqual('Actual is not a function'); @@ -461,55 +476,69 @@ describe("jasmine.Matchers", function() { }); - var spyMatch = function(value, spec) { - return new jasmine.Matchers(env, value, spec); - } - describe("wasCalled, wasNotCalled, wasCalledWith", function() { var TestClass; beforeEach(function() { TestClass = { someFunction: function() { } }; }); - - it('should always show an error if the actual is not a spy', function () { - expect(match(TestClass.someFunction).wasCalled()).toEqual(false); - var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; - expect(result.message).toEqual("Actual is not a spy."); + describe('without spies', function() { + it('should always show an error', function () { + expect(match(TestClass.someFunction).wasCalled()).toEqual(false); + var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; + expect(result.message).toEqual("Actual is not a spy."); - expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false); - result = mockSpec.addMatcherResult.mostRecentCall.args[0]; - expect(result.message).toEqual("Actual is not a spy."); + expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false); + result = mockSpec.addMatcherResult.mostRecentCall.args[0]; + expect(result.message).toEqual("Actual is not a spy."); + }); }); - it("should work for spys", function() { - TestClass.someFunction = jasmine.createSpy("My spy"); + describe('with spies', function () { - expect(match(TestClass.someFunction).wasCalled()).toEqual(false); - expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true); + beforeEach(function () { + TestClass.someFunction = jasmine.createSpy("My spy"); + }); - TestClass.someFunction(); - expect(match(TestClass.someFunction).wasCalled()).toEqual(true); - expect(function () { match(TestClass.someFunction).wasCalled('some arg');}).toThrow('wasCalled does not take arguments, use wasCalledWith'); - expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false); + it("should track if it was called", function() { + expect(match(TestClass.someFunction).wasCalled()).toEqual(false); + expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true); - TestClass.someFunction('a', 'b', 'c'); - expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true); + TestClass.someFunction(); + expect(match(TestClass.someFunction).wasCalled()).toEqual(true); + expect(function () { + match(TestClass.someFunction).wasCalled('some arg'); + }).toThrow('wasCalled does not take arguments, use wasCalledWith'); + expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false); + }); - var expected = match(TestClass.someFunction); - expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false); - result = mockSpec.addMatcherResult.mostRecentCall.args[0]; - expect(result.passed()).toEqual(false); + it('should return true if it was called with the expected args', function() { + TestClass.someFunction('a', 'b', 'c'); + expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true); + }); - TestClass.someFunction.reset(); - TestClass.someFunction('a', 'b', 'c'); - TestClass.someFunction('d', 'e', 'f'); - expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true); - expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true); - expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false); + it('should return false if it was not called with the expected args', function() { + TestClass.someFunction('a', 'b', 'c'); + var expected = match(TestClass.someFunction); + expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false); + var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; + expect(result.passed()).toEqual(false); + expect(result.expected).toEqual(['c', 'b', 'a']); + expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']); + }); + + it('should allow matches across multiple calls', function() { + var expected = match(TestClass.someFunction); + TestClass.someFunction('a', 'b', 'c'); + TestClass.someFunction('d', 'e', 'f'); + expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true); + expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true); + expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false); + }); }); }); + describe("wasCalledWith to build an ExpectationResult", function () { var TestClass; beforeEach(function() { @@ -561,4 +590,5 @@ describe("jasmine.Matchers", function() { expect(result.expected).toEqual(['a','b']); }); }); -}); +}) + ; diff --git a/src/Matchers.js b/src/Matchers.js index 0865217e..336bab59 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -24,18 +24,11 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) { return result; }; -/** - * Matcher that compares the actual to the expected using ===. - * - * @param expected - */ - - jasmine.Matchers.addMatcher = function(matcherName, options) { jasmine.Matchers.prototype[matcherName] = function () { jasmine.util.extend(this, options); - var expected = jasmine.util.argsToArray(arguments); - var args = [this.actual].concat(expected); + var matcherArgs = jasmine.util.argsToArray(arguments); + var args = [this.actual].concat(matcherArgs); var result = options.test.apply(this, args); var message; if (!result) { @@ -44,7 +37,7 @@ jasmine.Matchers.addMatcher = function(matcherName, options) { var expectationResult = new jasmine.ExpectationResult({ matcherName: matcherName, passed: result, - expected: expected, + expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], actual: this.actual, message: message }); @@ -120,7 +113,7 @@ jasmine.Matchers.addMatcher('toMatch', { return new RegExp(expected).test(actual); }, message: function(actual, expected) { - return actual + " does not match the regular expression " + new RegExp(expected).toString(); + return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString(); } }); @@ -134,7 +127,7 @@ jasmine.Matchers.addMatcher('toNotMatch', { return !(new RegExp(expected).test(actual)); }, message: function(actual, expected) { - return actual + " should not match " + new RegExp(expected).toString(); + return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString(); } });