From 328cc8998087e7d1490074e191e66f03b9c90912 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Thu, 29 Oct 2009 19:48:23 -0700 Subject: [PATCH] Add deadlyicon console fix for safari --- Rakefile | 2 +- contrib/ruby/jasmine_runner.rb | 3 +- doc/files.html | 14 +- doc/index.html | 2 +- doc/symbols/_global_.html | 2 +- doc/symbols/jasmine.Block.html | 2 +- doc/symbols/jasmine.Env.html | 2 +- doc/symbols/jasmine.JsApiReporter.html | 2 +- doc/symbols/jasmine.Matchers.html | 2 +- doc/symbols/jasmine.MultiReporter.html | 2 +- doc/symbols/jasmine.NestedResults.html | 2 +- doc/symbols/jasmine.Reporter.html | 2 +- doc/symbols/jasmine.Runner.html | 2 +- doc/symbols/jasmine.Spec.html | 2 +- doc/symbols/jasmine.Spy.html | 2 +- doc/symbols/jasmine.Suite.html | 2 +- doc/symbols/jasmine.html | 2 +- doc/symbols/jasmine.util.html | 2 +- doc/symbols/src/lib_TrivialReporter.js.html | 13 +- doc/symbols/src/lib_consolex.js.html | 29 + doc/symbols/src/lib_jasmine-0.10.0.js.html | 2190 +++++++++---------- examples/html/example_suite.html | 1 + examples/ruby/spec/jasmine_helper.rb | 4 +- lib/TrivialReporter.js | 12 +- lib/consolex.js | 22 + lib/jasmine-0.10.0.js | 2 +- spec/runner.html | 1 + 27 files changed, 1184 insertions(+), 1139 deletions(-) create mode 100644 doc/symbols/src/lib_consolex.js.html create mode 100644 lib/consolex.js diff --git a/Rakefile b/Rakefile index 767a100..5f457d8 100644 --- a/Rakefile +++ b/Rakefile @@ -67,7 +67,7 @@ jasmine.version_= { desc "Run jasmine tests of source via server" task :server do - jasmine_includes = lambda { jasmine_sources + ['lib/TrivialReporter.js'] } + jasmine_includes = lambda { jasmine_sources + ['lib/TrivialReporter.js', 'lib/consolex.js'] } start_jasmine_server(jasmine_includes) end diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 6d27b6b..b1808f2 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -66,7 +66,8 @@ module Jasmine @jasmine_files = jasmine_files || [ "/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first), "/__JASMINE_ROOT__/lib/TrivialReporter.js", - "/__JASMINE_ROOT__/lib/json2.js" + "/__JASMINE_ROOT__/lib/json2.js", + "/__JASMINE_ROOT__/lib/consolex.js", ] @stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"] + stylesheets end diff --git a/doc/files.html b/doc/files.html index 510186a..b4680cb 100644 --- a/doc/files.html +++ b/doc/files.html @@ -220,6 +220,18 @@ ul.inheritsList

File Index

+
+

lib/consolex.js

+ +
+ + + + +
+
+
+

lib/jasmine-0.10.0.js

@@ -260,7 +272,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index b1e631d..62be71a 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 01ae363..154e7f0 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 76656a8..09a203c 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 6ec9913..33e4b8f 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 321b133..df2a283 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index ee476e2..5293655 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -415,7 +415,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index ce6c848..65e21e9 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index e465877..b90b115 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 7affb2a..4680919 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index 7e8aad7..84c84e9 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index c91ff21..0a7b33e 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index 030cf38..a8d391b 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index f863e9c..30053d6 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 0949afe..fac89de 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 6dbd67b..2b93d8e 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 16:58:08 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Thu Oct 29 2009 19:47:57 GMT-0700 (PDT)
diff --git a/doc/symbols/src/lib_TrivialReporter.js.html b/doc/symbols/src/lib_TrivialReporter.js.html index fb10163..df0b881 100644 --- a/doc/symbols/src/lib_TrivialReporter.js.html +++ b/doc/symbols/src/lib_TrivialReporter.js.html @@ -123,15 +123,4 @@ 116 117 if (!paramMap["spec"]) return true; 118 return spec.getFullName().indexOf(paramMap["spec"]) == 0; -119 }; -120 -121 //protect against console.log incidents -122 if (!("console" in window) || !("firebug" in console)) { -123 var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; -124 window.console = {}; -125 for (var i = 0, len = names.length; i < len; ++i) { -126 window.console[names[i]] = function() { -127 }; -128 } -129 } -130 \ No newline at end of file +119 }; \ No newline at end of file diff --git a/doc/symbols/src/lib_consolex.js.html b/doc/symbols/src/lib_consolex.js.html new file mode 100644 index 0000000..33e9aa2 --- /dev/null +++ b/doc/symbols/src/lib_consolex.js.html @@ -0,0 +1,29 @@ +
  1 /** Console X
+  2   * http://github.com/deadlyicon/consolex.js
+  3   *
+  4   * prevents console errors and makes IE console objects true functions
+  5   *
+  6   */
+  7 (function() {
+  8   window.console || (window.console = {});
+  9 
+ 10   var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
+ 11   "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
+ 12 
+ 13   function emptyFunction(){}
+ 14 
+ 15   for (var i = 0; i < names.length; ++i){
+ 16     window.console[names[i]] || (window.console[names[i]] = emptyFunction);
+ 17     if (typeof window.console[names[i]] !== 'function')
+ 18       window.console[names[i]] = (function(method) {
+ 19           return function(){ return Function.prototype.apply.apply(method, [console,arguments]); };
+ 20         })(window.console[names[i]]);
+ 21   }
+ 22 })();
\ No newline at end of file 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 7238cc4..7ce6797 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": 1256860145 +539 "revision": 1256870671 540 }; 541 /** 542 * @namespace @@ -1193,1114 +1193,1112 @@ 1186 */ 1187 1188 jasmine.Matchers.addMatcher('wasCalled', { -1189 test: function() { +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')); 1193 } -1194 var actual = args.splice(0, 1)[0]; -1195 if (!actual || !actual.isSpy) { -1196 return false; -1197 } -1198 return actual.wasCalled; -1199 }, -1200 message: function() { -1201 var args = jasmine.util.argsToArray(arguments); -1202 var actual = args.splice(0, 1)[0]; -1203 var message; -1204 if (!actual || !actual.isSpy) { -1205 message = 'Actual is not a spy.'; -1206 } else { -1207 message = "Expected spy " + actual.identity + " to have been called."; -1208 } -1209 return message; -1210 } -1211 }); -1212 -1213 /** -1214 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. -1215 */ -1216 jasmine.Matchers.addMatcher('wasNotCalled', { -1217 test: function() { -1218 var args = jasmine.util.argsToArray(arguments); -1219 var actual = args.splice(0, 1)[0]; -1220 if (!actual || !actual.isSpy) { -1221 return false; -1222 } -1223 return !actual.wasCalled; -1224 }, -1225 message: function() { -1226 var args = jasmine.util.argsToArray(arguments); -1227 var actual = args.splice(0, 1)[0]; -1228 var message; +1194 return args.splice(0, 1)[0]; +1195 }, +1196 test: function() { +1197 var actual = this.getActual_.apply(this, arguments); +1198 if (!actual || !actual.isSpy) { +1199 return false; +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]; +1219 }, +1220 test: function() { +1221 var actual = this.getActual_.apply(this, arguments); +1222 if (!actual || !actual.isSpy) { +1223 return false; +1224 } +1225 return !actual.wasCalled; +1226 }, +1227 message: function() { +1228 var actual = this.getActual_.apply(this, arguments); 1229 if (!actual || !actual.isSpy) { -1230 message = 'Actual is not a spy.'; -1231 } else { -1232 message = "Expected spy " + actual.identity + " to not have been called."; -1233 } -1234 return message; -1235 } -1236 }); -1237 -1238 jasmine.Matchers.addMatcher('wasCalledWith', { -1239 test: function() { -1240 var args = jasmine.util.argsToArray(arguments); -1241 var actual = args.splice(0, 1)[0]; -1242 if (!actual || !actual.isSpy) { -1243 return false; -1244 } -1245 return this.env.contains_(actual.argsForCall, args); -1246 }, -1247 message: function() { -1248 var args = jasmine.util.argsToArray(arguments); -1249 var actual = args.splice(0, 1)[0]; -1250 var message; -1251 if (!actual || !actual.isSpy) { -1252 message = 'Actual is not a spy'; -1253 } else { -1254 message = "Expected spy to have been called with " + jasmine.pp(args) + " but was called with " + actual.argsForCall; -1255 } -1256 return message; -1257 } -1258 }); -1259 -1260 /** -1261 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +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 }); +1257 +1258 /** +1259 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +1260 * +1261 * @example 1262 * -1263 * @example -1264 * -1265 */ -1266 -1267 /** -1268 * Matcher that checks that the expected item is an element in the actual Array. -1269 * -1270 * @param {Object} item -1271 */ -1272 -1273 jasmine.Matchers.addMatcher('toContain', { -1274 test: function(actual, expected) { -1275 return this.env.contains_(actual, expected); -1276 }, -1277 message: function(actual, expected) { -1278 return 'Expected ' + jasmine.pp(actual) + ' to contain ' + jasmine.pp(expected); -1279 } -1280 }); -1281 -1282 /** -1283 * Matcher that checks that the expected item is NOT an element in the actual Array. -1284 * -1285 * @param {Object} item -1286 */ -1287 jasmine.Matchers.addMatcher('toNotContain', { -1288 test: function(actual, expected) { -1289 return !this.env.contains_(actual, expected); -1290 }, -1291 message: function(actual, expected) { -1292 return 'Expected ' + jasmine.pp(actual) + ' to not contain ' + jasmine.pp(expected); -1293 } -1294 }); -1295 -1296 jasmine.Matchers.addMatcher('toBeLessThan', { -1297 test: function(actual, expected) { -1298 return actual < expected; -1299 }, -1300 message: function(actual, expected) { -1301 return 'Expected ' + jasmine.pp(actual) + ' to be less than ' + jasmine.pp(expected); -1302 } -1303 }); -1304 -1305 jasmine.Matchers.addMatcher('toBeGreaterThan', { -1306 test: function(actual, expected) { -1307 return actual > expected; -1308 }, -1309 message: function(actual, expected) { -1310 return 'Expected ' + jasmine.pp(actual) + ' to be greater than ' + jasmine.pp(expected); -1311 } -1312 }); -1313 -1314 /** -1315 * Matcher that checks that the expected exception was thrown by the actual. -1316 * -1317 * @param {String} expectedException -1318 */ -1319 jasmine.Matchers.addMatcher('toThrow', { -1320 getException_: function(actual, expected) { -1321 var exception; -1322 if (typeof actual != 'function') { -1323 throw new Error('Actual is not a function'); -1324 } -1325 try { -1326 actual(); -1327 } catch (e) { -1328 exception = e; -1329 } -1330 return exception; -1331 }, -1332 test: function(actual, expected) { -1333 var result = false; -1334 var exception = this.getException_(actual, expected); -1335 if (exception) { -1336 result = (expected === undefined || this.env.equals_(exception.message || exception, expected.message || expected)); -1337 } -1338 return result; -1339 }, -1340 message: function(actual, expected) { -1341 var exception = this.getException_(actual, expected); -1342 if (exception && (expected === undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -1343 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); -1344 } else { -1345 return "Expected function to throw an exception."; -1346 } -1347 } -1348 }); -1349 -1350 jasmine.Matchers.Any = function(expectedClass) { -1351 this.expectedClass = expectedClass; -1352 }; -1353 -1354 jasmine.Matchers.Any.prototype.matches = function(other) { -1355 if (this.expectedClass == String) { -1356 return typeof other == 'string' || other instanceof String; -1357 } -1358 -1359 if (this.expectedClass == Number) { -1360 return typeof other == 'number' || other instanceof Number; -1361 } -1362 -1363 if (this.expectedClass == Function) { -1364 return typeof other == 'function' || other instanceof Function; -1365 } -1366 -1367 if (this.expectedClass == Object) { -1368 return typeof other == 'object'; -1369 } -1370 -1371 return other instanceof this.expectedClass; -1372 }; -1373 -1374 jasmine.Matchers.Any.prototype.toString = function() { -1375 return '<jasmine.any(' + this.expectedClass + ')>'; -1376 }; -1377 -1378 /** -1379 * @constructor -1380 */ -1381 jasmine.MultiReporter = function() { -1382 this.subReporters_ = []; -1383 }; -1384 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); -1385 -1386 jasmine.MultiReporter.prototype.addReporter = function(reporter) { -1387 this.subReporters_.push(reporter); -1388 }; -1389 -1390 (function() { -1391 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; -1392 for (var i = 0; i < functionNames.length; i++) { -1393 var functionName = functionNames[i]; -1394 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { -1395 return function() { -1396 for (var j = 0; j < this.subReporters_.length; j++) { -1397 var subReporter = this.subReporters_[j]; -1398 if (subReporter[functionName]) { -1399 subReporter[functionName].apply(subReporter, arguments); -1400 } -1401 } -1402 }; -1403 })(functionName); -1404 } -1405 })(); -1406 /** -1407 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults -1408 * -1409 * @constructor -1410 */ -1411 jasmine.NestedResults = function() { -1412 /** -1413 * The total count of results -1414 */ -1415 this.totalCount = 0; -1416 /** -1417 * Number of passed results -1418 */ -1419 this.passedCount = 0; -1420 /** -1421 * Number of failed results -1422 */ -1423 this.failedCount = 0; -1424 /** -1425 * Was this suite/spec skipped? -1426 */ -1427 this.skipped = false; -1428 /** -1429 * @ignore -1430 */ -1431 this.items_ = []; -1432 }; -1433 -1434 /** -1435 * Roll up the result counts. -1436 * -1437 * @param result -1438 */ -1439 jasmine.NestedResults.prototype.rollupCounts = function(result) { -1440 this.totalCount += result.totalCount; -1441 this.passedCount += result.passedCount; -1442 this.failedCount += result.failedCount; -1443 }; -1444 -1445 /** -1446 * Tracks a result's message. -1447 * @param message -1448 */ -1449 jasmine.NestedResults.prototype.log = function(message) { -1450 this.items_.push(new jasmine.MessageResult(message)); -1451 }; -1452 -1453 /** -1454 * Getter for the results: message & results. -1455 */ -1456 jasmine.NestedResults.prototype.getItems = function() { -1457 return this.items_; -1458 }; -1459 -1460 /** -1461 * Adds a result, tracking counts (total, passed, & failed) -1462 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result -1463 */ -1464 jasmine.NestedResults.prototype.addResult = function(result) { -1465 if (result.type != 'MessageResult') { -1466 if (result.items_) { -1467 this.rollupCounts(result); -1468 } else { -1469 this.totalCount++; -1470 if (result.passed()) { -1471 this.passedCount++; -1472 } else { -1473 this.failedCount++; -1474 } -1475 } -1476 } -1477 this.items_.push(result); -1478 }; -1479 -1480 /** -1481 * @returns {Boolean} True if <b>everything</b> below passed -1482 */ -1483 jasmine.NestedResults.prototype.passed = function() { -1484 return this.passedCount === this.totalCount; -1485 }; -1486 /** -1487 * Base class for pretty printing for expectation results. -1488 */ -1489 jasmine.PrettyPrinter = function() { -1490 this.ppNestLevel_ = 0; -1491 }; -1492 -1493 /** -1494 * Formats a value in a nice, human-readable string. -1495 * -1496 * @param value -1497 * @returns {String} -1498 */ -1499 jasmine.PrettyPrinter.prototype.format = function(value) { -1500 if (this.ppNestLevel_ > 40) { -1501 // return '(jasmine.pp nested too deeply!)'; -1502 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); -1503 } -1504 -1505 this.ppNestLevel_++; -1506 try { -1507 if (value === undefined) { -1508 this.emitScalar('undefined'); -1509 } else if (value === null) { -1510 this.emitScalar('null'); -1511 } else if (value.navigator && value.frames && value.setTimeout) { -1512 this.emitScalar('<window>'); -1513 } else if (value instanceof jasmine.Matchers.Any) { -1514 this.emitScalar(value.toString()); -1515 } else if (typeof value === 'string') { -1516 this.emitString(value); -1517 } else if (typeof value === 'function') { -1518 this.emitScalar('Function'); -1519 } else if (typeof value.nodeType === 'number') { -1520 this.emitScalar('HTMLNode'); -1521 } else if (value instanceof Date) { -1522 this.emitScalar('Date(' + value + ')'); -1523 } else if (value.__Jasmine_been_here_before__) { -1524 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); -1525 } else if (jasmine.isArray_(value) || typeof value == 'object') { -1526 value.__Jasmine_been_here_before__ = true; -1527 if (jasmine.isArray_(value)) { -1528 this.emitArray(value); -1529 } else { -1530 this.emitObject(value); -1531 } -1532 delete value.__Jasmine_been_here_before__; -1533 } else { -1534 this.emitScalar(value.toString()); -1535 } -1536 } finally { -1537 this.ppNestLevel_--; -1538 } -1539 }; -1540 -1541 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { -1542 for (var property in obj) { -1543 if (property == '__Jasmine_been_here_before__') continue; -1544 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); -1545 } -1546 }; -1547 -1548 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -1549 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -1550 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -1551 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; -1552 -1553 jasmine.StringPrettyPrinter = function() { -1554 jasmine.PrettyPrinter.call(this); -1555 -1556 this.string = ''; -1557 }; -1558 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); -1559 -1560 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { -1561 this.append(value); -1562 }; -1563 -1564 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { -1565 this.append("'" + value + "'"); -1566 }; -1567 -1568 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { -1569 this.append('[ '); -1570 for (var i = 0; i < array.length; i++) { -1571 if (i > 0) { -1572 this.append(', '); -1573 } -1574 this.format(array[i]); -1575 } -1576 this.append(' ]'); -1577 }; -1578 -1579 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { -1580 var self = this; -1581 this.append('{ '); -1582 var first = true; -1583 -1584 this.iterateObject(obj, function(property, isGetter) { -1585 if (first) { -1586 first = false; -1587 } else { -1588 self.append(', '); -1589 } -1590 -1591 self.append(property); -1592 self.append(' : '); -1593 if (isGetter) { -1594 self.append('<getter>'); -1595 } else { -1596 self.format(obj[property]); -1597 } -1598 }); -1599 -1600 this.append(' }'); -1601 }; -1602 -1603 jasmine.StringPrettyPrinter.prototype.append = function(value) { -1604 this.string += value; -1605 }; -1606 jasmine.Queue = function(env) { -1607 this.env = env; -1608 this.blocks = []; -1609 this.running = false; -1610 this.index = 0; -1611 this.offset = 0; -1612 }; -1613 -1614 jasmine.Queue.prototype.addBefore = function(block) { -1615 this.blocks.unshift(block); -1616 }; -1617 -1618 jasmine.Queue.prototype.add = function(block) { -1619 this.blocks.push(block); -1620 }; -1621 -1622 jasmine.Queue.prototype.insertNext = function(block) { -1623 this.blocks.splice((this.index + this.offset + 1), 0, block); -1624 this.offset++; -1625 }; -1626 -1627 jasmine.Queue.prototype.start = function(onComplete) { -1628 this.running = true; -1629 this.onComplete = onComplete; -1630 this.next_(); -1631 }; -1632 -1633 jasmine.Queue.prototype.isRunning = function() { -1634 return this.running; -1635 }; +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; +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 } +1364 +1365 if (this.expectedClass == Object) { +1366 return typeof other == 'object'; +1367 } +1368 +1369 return other instanceof this.expectedClass; +1370 }; +1371 +1372 jasmine.Matchers.Any.prototype.toString = function() { +1373 return '<jasmine.any(' + this.expectedClass + ')>'; +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 +1446 */ +1447 jasmine.NestedResults.prototype.log = function(message) { +1448 this.items_.push(new jasmine.MessageResult(message)); +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); +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 }; +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_--; +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_; +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; +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; +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.LOOP_DONT_RECURSE = true; -1638 -1639 jasmine.Queue.prototype.next_ = function() { -1640 var self = this; -1641 var goAgain = true; -1642 -1643 while (goAgain) { -1644 goAgain = false; -1645 -1646 if (self.index < self.blocks.length) { -1647 var calledSynchronously = true; -1648 var completedSynchronously = false; -1649 -1650 var onComplete = function () { -1651 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { -1652 completedSynchronously = true; -1653 return; -1654 } -1655 -1656 self.offset = 0; -1657 self.index++; -1658 -1659 var now = new Date().getTime(); -1660 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { -1661 self.env.lastUpdate = now; -1662 self.env.setTimeout(function() { -1663 self.next_(); -1664 }, 0); -1665 } else { -1666 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { -1667 goAgain = true; -1668 } else { -1669 self.next_(); -1670 } -1671 } -1672 }; -1673 self.blocks[self.index].execute(onComplete); -1674 -1675 calledSynchronously = false; -1676 if (completedSynchronously) { -1677 onComplete(); -1678 } -1679 -1680 } else { -1681 self.running = false; -1682 if (self.onComplete) { -1683 self.onComplete(); -1684 } -1685 } -1686 } -1687 }; -1688 -1689 jasmine.Queue.prototype.results = function() { -1690 var results = new jasmine.NestedResults(); -1691 for (var i = 0; i < this.blocks.length; i++) { -1692 if (this.blocks[i].results) { -1693 results.addResult(this.blocks[i].results()); -1694 } -1695 } -1696 return results; -1697 }; -1698 -1699 -1700 /* JasmineReporters.reporter -1701 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to -1702 * descendants of this object to do something with the results (see json_reporter.js) -1703 */ -1704 jasmine.Reporters = {}; -1705 -1706 jasmine.Reporters.reporter = function(callbacks) { -1707 var that = { -1708 callbacks: callbacks || {}, -1709 -1710 doCallback: function(callback, results) { -1711 if (callback) { -1712 callback(results); -1713 } -1714 }, -1715 -1716 reportRunnerResults: function(runner) { -1717 that.doCallback(that.callbacks.runnerCallback, runner); -1718 }, -1719 reportSuiteResults: function(suite) { -1720 that.doCallback(that.callbacks.suiteCallback, suite); -1721 }, -1722 reportSpecResults: function(spec) { -1723 that.doCallback(that.callbacks.specCallback, spec); -1724 }, -1725 log: function (str) { -1726 if (console && console.log) console.log(str); -1727 } -1728 }; -1729 -1730 return that; -1731 }; -1732 -1733 /** -1734 * Runner -1735 * -1736 * @constructor -1737 * @param {jasmine.Env} env -1738 */ -1739 jasmine.Runner = function(env) { -1740 var self = this; -1741 self.env = env; -1742 self.queue = new jasmine.Queue(env); -1743 self.before_ = []; -1744 self.after_ = []; -1745 self.suites_ = []; -1746 }; -1747 -1748 jasmine.Runner.prototype.execute = function() { -1749 var self = this; -1750 if (self.env.reporter.reportRunnerStarting) { -1751 self.env.reporter.reportRunnerStarting(this); -1752 } -1753 self.queue.start(function () { -1754 self.finishCallback(); -1755 }); -1756 }; -1757 -1758 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { -1759 beforeEachFunction.typeName = 'beforeEach'; -1760 this.before_.push(beforeEachFunction); -1761 }; -1762 -1763 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { -1764 afterEachFunction.typeName = 'afterEach'; -1765 this.after_.push(afterEachFunction); -1766 }; -1767 -1768 -1769 jasmine.Runner.prototype.finishCallback = function() { -1770 this.env.reporter.reportRunnerResults(this); -1771 }; -1772 -1773 jasmine.Runner.prototype.addSuite = function(suite) { -1774 this.suites_.push(suite); -1775 }; -1776 -1777 jasmine.Runner.prototype.add = function(block) { -1778 if (block instanceof jasmine.Suite) { -1779 this.addSuite(block); -1780 } -1781 this.queue.add(block); -1782 }; -1783 -1784 jasmine.Runner.prototype.specs = function () { -1785 var suites = this.suites(); -1786 var specs = []; -1787 for (var i = 0; i < suites.length; i++) { -1788 specs = specs.concat(suites[i].specs()); -1789 } -1790 return specs; -1791 }; -1792 -1793 -1794 jasmine.Runner.prototype.suites = function() { -1795 return this.suites_; -1796 }; -1797 -1798 jasmine.Runner.prototype.results = function() { -1799 return this.queue.results(); -1800 }; -1801 /** -1802 * Internal representation of a Jasmine specification, or test. -1803 * -1804 * @constructor -1805 * @param {jasmine.Env} env -1806 * @param {jasmine.Suite} suite -1807 * @param {String} description -1808 */ -1809 jasmine.Spec = function(env, suite, description) { -1810 if (!env) { -1811 throw new Error('jasmine.Env() required'); -1812 } -1813 ; -1814 if (!suite) { -1815 throw new Error('jasmine.Suite() required'); -1816 } -1817 ; -1818 var spec = this; -1819 spec.id = env.nextSpecId ? env.nextSpecId() : null; -1820 spec.env = env; -1821 spec.suite = suite; -1822 spec.description = description; -1823 spec.queue = new jasmine.Queue(env); -1824 -1825 spec.afterCallbacks = []; -1826 spec.spies_ = []; -1827 -1828 spec.results_ = new jasmine.NestedResults(); -1829 spec.results_.description = description; -1830 spec.matchersClass = null; -1831 }; -1832 -1833 jasmine.Spec.prototype.getFullName = function() { -1834 return this.suite.getFullName() + ' ' + this.description + '.'; -1835 }; -1836 -1837 -1838 jasmine.Spec.prototype.results = function() { -1839 return this.results_; -1840 }; -1841 -1842 jasmine.Spec.prototype.log = function(message) { -1843 return this.results_.log(message); -1844 }; -1845 -1846 jasmine.Spec.prototype.runs = function (func) { -1847 var block = new jasmine.Block(this.env, func, this); -1848 this.addToQueue(block); -1849 return this; -1850 }; -1851 -1852 jasmine.Spec.prototype.addToQueue = function (block) { -1853 if (this.queue.isRunning()) { -1854 this.queue.insertNext(block); -1855 } else { -1856 this.queue.add(block); -1857 } -1858 }; -1859 -1860 jasmine.Spec.prototype.addMatcherResult = function(result) { -1861 this.results_.addResult(result); -1862 }; -1863 -1864 jasmine.Spec.prototype.expect = function(actual) { -1865 return new (this.getMatchersClass_())(this.env, actual, this); -1866 }; -1867 -1868 jasmine.Spec.prototype.waits = function(timeout) { -1869 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); -1870 this.addToQueue(waitsFunc); -1871 return this; -1872 }; -1873 -1874 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { -1875 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); -1876 this.addToQueue(waitsForFunc); -1877 return this; -1878 }; -1879 -1880 jasmine.Spec.prototype.fail = function (e) { -1881 var expectationResult = new jasmine.ExpectationResult({ -1882 passed: false, -1883 message: e ? jasmine.util.formatException(e) : 'Exception' -1884 }); -1885 this.results_.addResult(expectationResult); -1886 }; -1887 -1888 jasmine.Spec.prototype.getMatchersClass_ = function() { -1889 return this.matchersClass || jasmine.Matchers; -1890 }; -1891 -1892 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -1893 var parent = this.getMatchersClass_(); -1894 var newMatchersClass = function() { -1895 parent.apply(this, arguments); -1896 }; -1897 jasmine.util.inherit(newMatchersClass, parent); -1898 for (var method in matchersPrototype) { -1899 newMatchersClass.prototype[method] = matchersPrototype[method]; -1900 } -1901 this.matchersClass = newMatchersClass; -1902 }; -1903 -1904 jasmine.Spec.prototype.finishCallback = function() { -1905 this.env.reporter.reportSpecResults(this); -1906 }; -1907 -1908 jasmine.Spec.prototype.finish = function(onComplete) { -1909 this.removeAllSpies(); -1910 this.finishCallback(); -1911 if (onComplete) { -1912 onComplete(); -1913 } -1914 }; +1637 jasmine.Queue.prototype.next_ = function() { +1638 var self = this; +1639 var goAgain = true; +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 }; +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 } +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); +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) { 1915 -1916 jasmine.Spec.prototype.after = function(doAfter, test) { -1917 -1918 if (this.queue.isRunning()) { -1919 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -1920 } else { -1921 this.afterCallbacks.unshift(doAfter); -1922 } -1923 }; -1924 -1925 jasmine.Spec.prototype.execute = function(onComplete) { -1926 var spec = this; -1927 if (!spec.env.specFilter(spec)) { -1928 spec.results_.skipped = true; -1929 spec.finish(onComplete); -1930 return; -1931 } -1932 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +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; 1933 -1934 spec.env.currentSpec = spec; +1934 spec.addBeforesAndAftersToQueue(); 1935 -1936 spec.addBeforesAndAftersToQueue(); -1937 -1938 spec.queue.start(function () { -1939 spec.finish(onComplete); -1940 }); -1941 }; -1942 -1943 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -1944 var runner = this.env.currentRunner(); -1945 for (var suite = this.suite; suite; suite = suite.parentSuite) { -1946 for (var i = 0; i < suite.before_.length; i++) { -1947 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -1948 } -1949 } -1950 for (var i = 0; i < runner.before_.length; i++) { -1951 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -1952 } -1953 for (i = 0; i < this.afterCallbacks.length; i++) { -1954 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -1955 } -1956 for (suite = this.suite; suite; suite = suite.parentSuite) { -1957 for (var i = 0; i < suite.after_.length; i++) { -1958 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -1959 } -1960 } -1961 for (var i = 0; i < runner.after_.length; i++) { -1962 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -1963 } -1964 }; -1965 -1966 jasmine.Spec.prototype.explodes = function() { -1967 throw 'explodes function should not have been called'; -1968 }; -1969 -1970 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -1971 if (obj == undefined) { -1972 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -1973 } -1974 -1975 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -1976 throw methodName + '() method does not exist'; -1977 } -1978 -1979 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -1980 throw new Error(methodName + ' has already been spied upon'); -1981 } +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 } +1980 +1981 var spyObj = jasmine.createSpy(methodName); 1982 -1983 var spyObj = jasmine.createSpy(methodName); -1984 -1985 this.spies_.push(spyObj); -1986 spyObj.baseObj = obj; -1987 spyObj.methodName = methodName; -1988 spyObj.originalValue = obj[methodName]; +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 obj[methodName] = spyObj; -1991 -1992 return spyObj; -1993 }; -1994 -1995 jasmine.Spec.prototype.removeAllSpies = function() { -1996 for (var i = 0; i < this.spies_.length; i++) { -1997 var spy = this.spies_[i]; -1998 spy.baseObj[spy.methodName] = spy.originalValue; -1999 } -2000 this.spies_ = []; -2001 }; -2002 -2003 /** -2004 * Internal representation of a Jasmine suite. -2005 * -2006 * @constructor -2007 * @param {jasmine.Env} env -2008 * @param {String} description -2009 * @param {Function} specDefinitions -2010 * @param {jasmine.Suite} parentSuite -2011 */ -2012 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { -2013 var self = this; -2014 self.id = env.nextSuiteId ? env.nextSuiteId() : null; -2015 self.description = description; -2016 self.queue = new jasmine.Queue(env); -2017 self.parentSuite = parentSuite; -2018 self.env = env; -2019 self.before_ = []; -2020 self.after_ = []; -2021 self.specs_ = []; -2022 }; -2023 -2024 jasmine.Suite.prototype.getFullName = function() { -2025 var fullName = this.description; -2026 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { -2027 fullName = parentSuite.description + ' ' + fullName; -2028 } -2029 return fullName; -2030 }; -2031 -2032 jasmine.Suite.prototype.finish = function(onComplete) { -2033 this.env.reporter.reportSuiteResults(this); -2034 this.finished = true; -2035 if (typeof(onComplete) == 'function') { -2036 onComplete(); -2037 } -2038 }; -2039 -2040 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { -2041 beforeEachFunction.typeName = 'beforeEach'; -2042 this.before_.push(beforeEachFunction); -2043 }; -2044 -2045 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { -2046 afterEachFunction.typeName = 'afterEach'; -2047 this.after_.push(afterEachFunction); -2048 }; -2049 -2050 jasmine.Suite.prototype.results = function() { -2051 return this.queue.results(); -2052 }; -2053 -2054 jasmine.Suite.prototype.add = function(block) { -2055 if (block instanceof jasmine.Suite) { -2056 this.env.currentRunner().addSuite(block); -2057 } else { -2058 this.specs_.push(block); -2059 } -2060 this.queue.add(block); -2061 }; -2062 -2063 jasmine.Suite.prototype.specs = function() { -2064 return this.specs_; -2065 }; -2066 -2067 jasmine.Suite.prototype.execute = function(onComplete) { -2068 var self = this; -2069 this.queue.start(function () { -2070 self.finish(onComplete); -2071 }); -2072 }; -2073 jasmine.WaitsBlock = function(env, timeout, spec) { -2074 this.timeout = timeout; -2075 jasmine.Block.call(this, env, null, spec); -2076 }; +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_; +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.util.inherit(jasmine.WaitsBlock, jasmine.Block); -2079 -2080 jasmine.WaitsBlock.prototype.execute = function (onComplete) { -2081 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); -2082 this.env.setTimeout(function () { -2083 onComplete(); -2084 }, this.timeout); -2085 }; -2086 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { -2087 this.timeout = timeout; -2088 this.latchFunction = latchFunction; -2089 this.message = message; -2090 this.totalTimeSpentWaitingForLatch = 0; -2091 jasmine.Block.call(this, env, null, spec); -2092 }; +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); +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.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +2094 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; 2095 -2096 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; -2097 -2098 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { -2099 var self = this; -2100 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); -2101 var latchFunctionResult; -2102 try { -2103 latchFunctionResult = self.latchFunction.apply(self.spec); -2104 } catch (e) { -2105 self.spec.fail(e); -2106 onComplete(); -2107 return; -2108 } -2109 -2110 if (latchFunctionResult) { -2111 onComplete(); -2112 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { -2113 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); -2114 self.spec.fail({ -2115 name: 'timeout', -2116 message: message -2117 }); -2118 self.spec._next(); -2119 } else { -2120 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; -2121 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); -2122 } -2123 }; -2124 // Mock setTimeout, clearTimeout -2125 // Contributed by Pivotal Computer Systems, www.pivotalsf.com -2126 -2127 jasmine.FakeTimer = function() { -2128 this.reset(); -2129 -2130 var self = this; -2131 self.setTimeout = function(funcToCall, millis) { -2132 self.timeoutsMade++; -2133 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); -2134 return self.timeoutsMade; -2135 }; -2136 -2137 self.setInterval = function(funcToCall, millis) { -2138 self.timeoutsMade++; -2139 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); -2140 return self.timeoutsMade; -2141 }; -2142 -2143 self.clearTimeout = function(timeoutKey) { -2144 self.scheduledFunctions[timeoutKey] = undefined; -2145 }; -2146 -2147 self.clearInterval = function(timeoutKey) { -2148 self.scheduledFunctions[timeoutKey] = undefined; -2149 }; +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(); +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 }; -2152 -2153 jasmine.FakeTimer.prototype.reset = function() { -2154 this.timeoutsMade = 0; -2155 this.scheduledFunctions = {}; -2156 this.nowMillis = 0; -2157 }; -2158 -2159 jasmine.FakeTimer.prototype.tick = function(millis) { -2160 var oldMillis = this.nowMillis; -2161 var newMillis = oldMillis + millis; -2162 this.runFunctionsWithinRange(oldMillis, newMillis); -2163 this.nowMillis = newMillis; -2164 }; -2165 -2166 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { -2167 var scheduledFunc; -2168 var funcsToRun = []; -2169 for (var timeoutKey in this.scheduledFunctions) { -2170 scheduledFunc = this.scheduledFunctions[timeoutKey]; -2171 if (scheduledFunc != undefined && -2172 scheduledFunc.runAtMillis >= oldMillis && -2173 scheduledFunc.runAtMillis <= nowMillis) { -2174 funcsToRun.push(scheduledFunc); -2175 this.scheduledFunctions[timeoutKey] = undefined; -2176 } -2177 } -2178 -2179 if (funcsToRun.length > 0) { -2180 funcsToRun.sort(function(a, b) { -2181 return a.runAtMillis - b.runAtMillis; -2182 }); -2183 for (var i = 0; i < funcsToRun.length; ++i) { -2184 try { -2185 var funcToRun = funcsToRun[i]; -2186 this.nowMillis = funcToRun.runAtMillis; -2187 funcToRun.funcToCall(); -2188 if (funcToRun.recurring) { -2189 this.scheduleFunction(funcToRun.timeoutKey, -2190 funcToRun.funcToCall, -2191 funcToRun.millis, -2192 true); -2193 } -2194 } catch(e) { -2195 } -2196 } -2197 this.runFunctionsWithinRange(oldMillis, nowMillis); -2198 } -2199 }; -2200 -2201 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { -2202 this.scheduledFunctions[timeoutKey] = { -2203 runAtMillis: this.nowMillis + millis, -2204 funcToCall: funcToCall, -2205 recurring: recurring, -2206 timeoutKey: timeoutKey, -2207 millis: millis -2208 }; -2209 }; -2210 -2211 -2212 jasmine.Clock = { -2213 defaultFakeTimer: new jasmine.FakeTimer(), -2214 -2215 reset: function() { -2216 jasmine.Clock.assertInstalled(); -2217 jasmine.Clock.defaultFakeTimer.reset(); -2218 }, -2219 -2220 tick: function(millis) { -2221 jasmine.Clock.assertInstalled(); -2222 jasmine.Clock.defaultFakeTimer.tick(millis); -2223 }, -2224 -2225 runFunctionsWithinRange: function(oldMillis, nowMillis) { -2226 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); -2227 }, -2228 -2229 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { -2230 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); -2231 }, -2232 -2233 useMock: function() { -2234 var spec = jasmine.getEnv().currentSpec; -2235 spec.after(jasmine.Clock.uninstallMock); -2236 -2237 jasmine.Clock.installMock(); -2238 }, -2239 -2240 installMock: function() { -2241 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; -2242 }, -2243 -2244 uninstallMock: function() { -2245 jasmine.Clock.assertInstalled(); -2246 jasmine.Clock.installed = jasmine.Clock.real; -2247 }, -2248 -2249 real: { -2250 setTimeout: window.setTimeout, -2251 clearTimeout: window.clearTimeout, -2252 setInterval: window.setInterval, -2253 clearInterval: window.clearInterval -2254 }, -2255 -2256 assertInstalled: function() { -2257 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { -2258 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -2259 } -2260 }, -2261 -2262 installed: null -2263 }; -2264 jasmine.Clock.installed = jasmine.Clock.real; -2265 -2266 //else for IE support -2267 window.setTimeout = function(funcToCall, millis) { -2268 if (jasmine.Clock.installed.setTimeout.apply) { -2269 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -2270 } else { -2271 return jasmine.Clock.installed.setTimeout(funcToCall, millis); -2272 } -2273 }; -2274 -2275 window.setInterval = function(funcToCall, millis) { -2276 if (jasmine.Clock.installed.setInterval.apply) { -2277 return jasmine.Clock.installed.setInterval.apply(this, arguments); -2278 } else { -2279 return jasmine.Clock.installed.setInterval(funcToCall, millis); -2280 } -2281 }; -2282 -2283 window.clearTimeout = function(timeoutKey) { -2284 if (jasmine.Clock.installed.clearTimeout.apply) { -2285 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -2286 } else { -2287 return jasmine.Clock.installed.clearTimeout(timeoutKey); -2288 } -2289 }; -2290 -2291 window.clearInterval = function(timeoutKey) { -2292 if (jasmine.Clock.installed.clearTimeout.apply) { -2293 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -2294 } else { -2295 return jasmine.Clock.installed.clearInterval(timeoutKey); -2296 } -2297 }; -2298 -2299 \ No newline at end of file +2151 jasmine.FakeTimer.prototype.reset = function() { +2152 this.timeoutsMade = 0; +2153 this.scheduledFunctions = {}; +2154 this.nowMillis = 0; +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); +2229 }, +2230 +2231 useMock: function() { +2232 var spec = jasmine.getEnv().currentSpec; +2233 spec.after(jasmine.Clock.uninstallMock); +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; +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 diff --git a/examples/html/example_suite.html b/examples/html/example_suite.html index 7d98f06..825ec2c 100644 --- a/examples/html/example_suite.html +++ b/examples/html/example_suite.html @@ -6,6 +6,7 @@ + +