booster 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +106 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +174 -0
  6. data/Rakefile +7 -0
  7. data/booster.gemspec +24 -0
  8. data/booster.tmbundle/Snippets/untitled.tmSnippet +14 -0
  9. data/booster.tmbundle/Syntaxes/Booster.tmLanguage +46 -0
  10. data/booster.tmbundle/info.plist +10 -0
  11. data/lib/assets/javascripts/booster-core.js +5 -0
  12. data/lib/assets/javascripts/booster-support.js +1 -0
  13. data/lib/assets/javascripts/booster.js +2 -0
  14. data/lib/assets/javascripts/booster/collection.js.boost +1 -0
  15. data/lib/assets/javascripts/booster/model.js.boost +30 -0
  16. data/lib/assets/javascripts/booster/router.js.boost +107 -0
  17. data/lib/assets/javascripts/booster/support/binding.js.boost +1 -0
  18. data/lib/assets/javascripts/booster/support/helpers.js.boost +109 -0
  19. data/lib/assets/javascripts/booster/support/i18n.js.boost +136 -0
  20. data/lib/assets/javascripts/booster/support/observer.js.boost +81 -0
  21. data/lib/assets/javascripts/booster/support/schema.js.boost +117 -0
  22. data/lib/assets/javascripts/booster/view.js.boost +45 -0
  23. data/lib/assets/javascripts/booster/views/composite.js.boost +59 -0
  24. data/lib/assets/javascripts/booster/views/layout.js.boost +94 -0
  25. data/lib/booster.rb +7 -0
  26. data/lib/booster/engine.rb +8 -0
  27. data/lib/booster/handlebars.rb +50 -0
  28. data/lib/booster/template.rb +59 -0
  29. data/lib/booster/version.rb +3 -0
  30. data/test/booster/tilt_test.rb +35 -0
  31. data/test/dummy/Rakefile +7 -0
  32. data/test/dummy/app/assets/javascripts/application.js.boost +18 -0
  33. data/test/dummy/app/assets/javascripts/booster/support/helpers_spec.js.boost +69 -0
  34. data/test/dummy/app/assets/javascripts/booster/support/i18n_spec.js.boost +0 -0
  35. data/test/dummy/app/assets/javascripts/booster/support/observer_spec.js.boost +56 -0
  36. data/test/dummy/app/assets/javascripts/booster/support/router_spec.js.boost +19 -0
  37. data/test/dummy/app/assets/javascripts/booster/support/schema_spec.js.boost +79 -0
  38. data/test/dummy/app/assets/javascripts/booster/views/layout_spec.js.boost +30 -0
  39. data/test/dummy/app/controllers/application_controller.rb +7 -0
  40. data/test/dummy/app/views/layouts/application.html.erb +29 -0
  41. data/test/dummy/config.ru +4 -0
  42. data/test/dummy/config/application.rb +30 -0
  43. data/test/dummy/config/boot.rb +10 -0
  44. data/test/dummy/config/environment.rb +5 -0
  45. data/test/dummy/config/environments/development.rb +27 -0
  46. data/test/dummy/config/environments/production.rb +29 -0
  47. data/test/dummy/config/environments/test.rb +34 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/inflections.rb +10 -0
  50. data/test/dummy/config/initializers/mime_types.rb +5 -0
  51. data/test/dummy/config/initializers/secret_token.rb +7 -0
  52. data/test/dummy/config/initializers/session_store.rb +8 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +5 -0
  55. data/test/dummy/config/routes.rb +3 -0
  56. data/test/dummy/public/404.html +26 -0
  57. data/test/dummy/public/422.html +26 -0
  58. data/test/dummy/public/500.html +26 -0
  59. data/test/dummy/public/favicon.ico +0 -0
  60. data/test/dummy/script/rails +6 -0
  61. data/test/test_helper.rb +4 -0
  62. data/vendor/assets/javascripts/backbone.js +1158 -0
  63. data/vendor/assets/javascripts/handlebars-helpers.js +56 -0
  64. data/vendor/assets/javascripts/handlebars-vm.js +191 -0
  65. data/vendor/assets/javascripts/handlebars.js +1561 -0
  66. data/vendor/assets/javascripts/jasmine-html.js +190 -0
  67. data/vendor/assets/javascripts/jasmine-jquery.js +288 -0
  68. data/vendor/assets/javascripts/jasmine.js +2471 -0
  69. data/vendor/assets/javascripts/stitch.js +57 -0
  70. data/vendor/assets/javascripts/underscore.js +981 -0
  71. data/vendor/assets/stylesheets/jasmine.css +166 -0
  72. metadata +172 -0
@@ -0,0 +1,2471 @@
1
+ var isCommonJS = typeof window == "undefined";
2
+
3
+ /**
4
+ * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
5
+ *
6
+ * @namespace
7
+ */
8
+ var jasmine = {};
9
+ if (isCommonJS) exports.jasmine = jasmine;
10
+ /**
11
+ * @private
12
+ */
13
+ jasmine.unimplementedMethod_ = function() {
14
+ throw new Error("unimplemented method");
15
+ };
16
+
17
+ /**
18
+ * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
19
+ * a plain old variable and may be redefined by somebody else.
20
+ *
21
+ * @private
22
+ */
23
+ jasmine.undefined = jasmine.___undefined___;
24
+
25
+ /**
26
+ * Show diagnostic messages in the console if set to true
27
+ *
28
+ */
29
+ jasmine.VERBOSE = false;
30
+
31
+ /**
32
+ * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
33
+ *
34
+ */
35
+ jasmine.DEFAULT_UPDATE_INTERVAL = 250;
36
+
37
+ /**
38
+ * Default timeout interval in milliseconds for waitsFor() blocks.
39
+ */
40
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
41
+
42
+ jasmine.getGlobal = function() {
43
+ function getGlobal() {
44
+ return this;
45
+ }
46
+
47
+ return getGlobal();
48
+ };
49
+
50
+ /**
51
+ * Allows for bound functions to be compared. Internal use only.
52
+ *
53
+ * @ignore
54
+ * @private
55
+ * @param base {Object} bound 'this' for the function
56
+ * @param name {Function} function to find
57
+ */
58
+ jasmine.bindOriginal_ = function(base, name) {
59
+ var original = base[name];
60
+ if (original.apply) {
61
+ return function() {
62
+ return original.apply(base, arguments);
63
+ };
64
+ } else {
65
+ // IE support
66
+ return jasmine.getGlobal()[name];
67
+ }
68
+ };
69
+
70
+ jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
71
+ jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
72
+ jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
73
+ jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
74
+
75
+ jasmine.MessageResult = function(values) {
76
+ this.type = 'log';
77
+ this.values = values;
78
+ this.trace = new Error(); // todo: test better
79
+ };
80
+
81
+ jasmine.MessageResult.prototype.toString = function() {
82
+ var text = "";
83
+ for (var i = 0; i < this.values.length; i++) {
84
+ if (i > 0) text += " ";
85
+ if (jasmine.isString_(this.values[i])) {
86
+ text += this.values[i];
87
+ } else {
88
+ text += jasmine.pp(this.values[i]);
89
+ }
90
+ }
91
+ return text;
92
+ };
93
+
94
+ jasmine.ExpectationResult = function(params) {
95
+ this.type = 'expect';
96
+ this.matcherName = params.matcherName;
97
+ this.passed_ = params.passed;
98
+ this.expected = params.expected;
99
+ this.actual = params.actual;
100
+ this.message = this.passed_ ? 'Passed.' : params.message;
101
+
102
+ var trace = (params.trace || new Error(this.message));
103
+ this.trace = this.passed_ ? '' : trace;
104
+ };
105
+
106
+ jasmine.ExpectationResult.prototype.toString = function () {
107
+ return this.message;
108
+ };
109
+
110
+ jasmine.ExpectationResult.prototype.passed = function () {
111
+ return this.passed_;
112
+ };
113
+
114
+ /**
115
+ * Getter for the Jasmine environment. Ensures one gets created
116
+ */
117
+ jasmine.getEnv = function() {
118
+ var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
119
+ return env;
120
+ };
121
+
122
+ /**
123
+ * @ignore
124
+ * @private
125
+ * @param value
126
+ * @returns {Boolean}
127
+ */
128
+ jasmine.isArray_ = function(value) {
129
+ return jasmine.isA_("Array", value);
130
+ };
131
+
132
+ /**
133
+ * @ignore
134
+ * @private
135
+ * @param value
136
+ * @returns {Boolean}
137
+ */
138
+ jasmine.isString_ = function(value) {
139
+ return jasmine.isA_("String", value);
140
+ };
141
+
142
+ /**
143
+ * @ignore
144
+ * @private
145
+ * @param value
146
+ * @returns {Boolean}
147
+ */
148
+ jasmine.isNumber_ = function(value) {
149
+ return jasmine.isA_("Number", value);
150
+ };
151
+
152
+ /**
153
+ * @ignore
154
+ * @private
155
+ * @param {String} typeName
156
+ * @param value
157
+ * @returns {Boolean}
158
+ */
159
+ jasmine.isA_ = function(typeName, value) {
160
+ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
161
+ };
162
+
163
+ /**
164
+ * Pretty printer for expecations. Takes any object and turns it into a human-readable string.
165
+ *
166
+ * @param value {Object} an object to be outputted
167
+ * @returns {String}
168
+ */
169
+ jasmine.pp = function(value) {
170
+ var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
171
+ stringPrettyPrinter.format(value);
172
+ return stringPrettyPrinter.string;
173
+ };
174
+
175
+ /**
176
+ * Returns true if the object is a DOM Node.
177
+ *
178
+ * @param {Object} obj object to check
179
+ * @returns {Boolean}
180
+ */
181
+ jasmine.isDomNode = function(obj) {
182
+ return obj.nodeType > 0;
183
+ };
184
+
185
+ /**
186
+ * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
187
+ *
188
+ * @example
189
+ * // don't care about which function is passed in, as long as it's a function
190
+ * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));
191
+ *
192
+ * @param {Class} clazz
193
+ * @returns matchable object of the type clazz
194
+ */
195
+ jasmine.any = function(clazz) {
196
+ return new jasmine.Matchers.Any(clazz);
197
+ };
198
+
199
+ /**
200
+ * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
201
+ *
202
+ * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
203
+ * expectation syntax. Spies can be checked if they were called or not and what the calling params were.
204
+ *
205
+ * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs).
206
+ *
207
+ * Spies are torn down at the end of every spec.
208
+ *
209
+ * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
210
+ *
211
+ * @example
212
+ * // a stub
213
+ * var myStub = jasmine.createSpy('myStub'); // can be used anywhere
214
+ *
215
+ * // spy example
216
+ * var foo = {
217
+ * not: function(bool) { return !bool; }
218
+ * }
219
+ *
220
+ * // actual foo.not will not be called, execution stops
221
+ * spyOn(foo, 'not');
222
+
223
+ // foo.not spied upon, execution will continue to implementation
224
+ * spyOn(foo, 'not').andCallThrough();
225
+ *
226
+ * // fake example
227
+ * var foo = {
228
+ * not: function(bool) { return !bool; }
229
+ * }
230
+ *
231
+ * // foo.not(val) will return val
232
+ * spyOn(foo, 'not').andCallFake(function(value) {return value;});
233
+ *
234
+ * // mock example
235
+ * foo.not(7 == 7);
236
+ * expect(foo.not).toHaveBeenCalled();
237
+ * expect(foo.not).toHaveBeenCalledWith(true);
238
+ *
239
+ * @constructor
240
+ * @see spyOn, jasmine.createSpy, jasmine.createSpyObj
241
+ * @param {String} name
242
+ */
243
+ jasmine.Spy = function(name) {
244
+ /**
245
+ * The name of the spy, if provided.
246
+ */
247
+ this.identity = name || 'unknown';
248
+ /**
249
+ * Is this Object a spy?
250
+ */
251
+ this.isSpy = true;
252
+ /**
253
+ * The actual function this spy stubs.
254
+ */
255
+ this.plan = function() {
256
+ };
257
+ /**
258
+ * Tracking of the most recent call to the spy.
259
+ * @example
260
+ * var mySpy = jasmine.createSpy('foo');
261
+ * mySpy(1, 2);
262
+ * mySpy.mostRecentCall.args = [1, 2];
263
+ */
264
+ this.mostRecentCall = {};
265
+
266
+ /**
267
+ * Holds arguments for each call to the spy, indexed by call count
268
+ * @example
269
+ * var mySpy = jasmine.createSpy('foo');
270
+ * mySpy(1, 2);
271
+ * mySpy(7, 8);
272
+ * mySpy.mostRecentCall.args = [7, 8];
273
+ * mySpy.argsForCall[0] = [1, 2];
274
+ * mySpy.argsForCall[1] = [7, 8];
275
+ */
276
+ this.argsForCall = [];
277
+ this.calls = [];
278
+ };
279
+
280
+ /**
281
+ * Tells a spy to call through to the actual implemenatation.
282
+ *
283
+ * @example
284
+ * var foo = {
285
+ * bar: function() { // do some stuff }
286
+ * }
287
+ *
288
+ * // defining a spy on an existing property: foo.bar
289
+ * spyOn(foo, 'bar').andCallThrough();
290
+ */
291
+ jasmine.Spy.prototype.andCallThrough = function() {
292
+ this.plan = this.originalValue;
293
+ return this;
294
+ };
295
+
296
+ /**
297
+ * For setting the return value of a spy.
298
+ *
299
+ * @example
300
+ * // defining a spy from scratch: foo() returns 'baz'
301
+ * var foo = jasmine.createSpy('spy on foo').andReturn('baz');
302
+ *
303
+ * // defining a spy on an existing property: foo.bar() returns 'baz'
304
+ * spyOn(foo, 'bar').andReturn('baz');
305
+ *
306
+ * @param {Object} value
307
+ */
308
+ jasmine.Spy.prototype.andReturn = function(value) {
309
+ this.plan = function() {
310
+ return value;
311
+ };
312
+ return this;
313
+ };
314
+
315
+ /**
316
+ * For throwing an exception when a spy is called.
317
+ *
318
+ * @example
319
+ * // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
320
+ * var foo = jasmine.createSpy('spy on foo').andThrow('baz');
321
+ *
322
+ * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
323
+ * spyOn(foo, 'bar').andThrow('baz');
324
+ *
325
+ * @param {String} exceptionMsg
326
+ */
327
+ jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
328
+ this.plan = function() {
329
+ throw exceptionMsg;
330
+ };
331
+ return this;
332
+ };
333
+
334
+ /**
335
+ * Calls an alternate implementation when a spy is called.
336
+ *
337
+ * @example
338
+ * var baz = function() {
339
+ * // do some stuff, return something
340
+ * }
341
+ * // defining a spy from scratch: foo() calls the function baz
342
+ * var foo = jasmine.createSpy('spy on foo').andCall(baz);
343
+ *
344
+ * // defining a spy on an existing property: foo.bar() calls an anonymnous function
345
+ * spyOn(foo, 'bar').andCall(function() { return 'baz';} );
346
+ *
347
+ * @param {Function} fakeFunc
348
+ */
349
+ jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
350
+ this.plan = fakeFunc;
351
+ return this;
352
+ };
353
+
354
+ /**
355
+ * Resets all of a spy's the tracking variables so that it can be used again.
356
+ *
357
+ * @example
358
+ * spyOn(foo, 'bar');
359
+ *
360
+ * foo.bar();
361
+ *
362
+ * expect(foo.bar.callCount).toEqual(1);
363
+ *
364
+ * foo.bar.reset();
365
+ *
366
+ * expect(foo.bar.callCount).toEqual(0);
367
+ */
368
+ jasmine.Spy.prototype.reset = function() {
369
+ this.wasCalled = false;
370
+ this.callCount = 0;
371
+ this.argsForCall = [];
372
+ this.calls = [];
373
+ this.mostRecentCall = {};
374
+ };
375
+
376
+ jasmine.createSpy = function(name) {
377
+
378
+ var spyObj = function() {
379
+ spyObj.wasCalled = true;
380
+ spyObj.callCount++;
381
+ var args = jasmine.util.argsToArray(arguments);
382
+ spyObj.mostRecentCall.object = this;
383
+ spyObj.mostRecentCall.args = args;
384
+ spyObj.argsForCall.push(args);
385
+ spyObj.calls.push({object: this, args: args});
386
+ return spyObj.plan.apply(this, arguments);
387
+ };
388
+
389
+ var spy = new jasmine.Spy(name);
390
+
391
+ for (var prop in spy) {
392
+ spyObj[prop] = spy[prop];
393
+ }
394
+
395
+ spyObj.reset();
396
+
397
+ return spyObj;
398
+ };
399
+
400
+ /**
401
+ * Determines whether an object is a spy.
402
+ *
403
+ * @param {jasmine.Spy|Object} putativeSpy
404
+ * @returns {Boolean}
405
+ */
406
+ jasmine.isSpy = function(putativeSpy) {
407
+ return putativeSpy && putativeSpy.isSpy;
408
+ };
409
+
410
+ /**
411
+ * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
412
+ * large in one call.
413
+ *
414
+ * @param {String} baseName name of spy class
415
+ * @param {Array} methodNames array of names of methods to make spies
416
+ */
417
+ jasmine.createSpyObj = function(baseName, methodNames) {
418
+ if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
419
+ throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
420
+ }
421
+ var obj = {};
422
+ for (var i = 0; i < methodNames.length; i++) {
423
+ obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
424
+ }
425
+ return obj;
426
+ };
427
+
428
+ /**
429
+ * All parameters are pretty-printed and concatenated together, then written to the current spec's output.
430
+ *
431
+ * Be careful not to leave calls to <code>jasmine.log</code> in production code.
432
+ */
433
+ jasmine.log = function() {
434
+ var spec = jasmine.getEnv().currentSpec;
435
+ spec.log.apply(spec, arguments);
436
+ };
437
+
438
+ /**
439
+ * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
440
+ *
441
+ * @example
442
+ * // spy example
443
+ * var foo = {
444
+ * not: function(bool) { return !bool; }
445
+ * }
446
+ * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
447
+ *
448
+ * @see jasmine.createSpy
449
+ * @param obj
450
+ * @param methodName
451
+ * @returns a Jasmine spy that can be chained with all spy methods
452
+ */
453
+ var spyOn = function(obj, methodName) {
454
+ return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
455
+ };
456
+ if (isCommonJS) exports.spyOn = spyOn;
457
+
458
+ /**
459
+ * Creates a Jasmine spec that will be added to the current suite.
460
+ *
461
+ * // TODO: pending tests
462
+ *
463
+ * @example
464
+ * it('should be true', function() {
465
+ * expect(true).toEqual(true);
466
+ * });
467
+ *
468
+ * @param {String} desc description of this specification
469
+ * @param {Function} func defines the preconditions and expectations of the spec
470
+ */
471
+ var it = function(desc, func) {
472
+ return jasmine.getEnv().it(desc, func);
473
+ };
474
+ if (isCommonJS) exports.it = it;
475
+
476
+ /**
477
+ * Creates a <em>disabled</em> Jasmine spec.
478
+ *
479
+ * A convenience method that allows existing specs to be disabled temporarily during development.
480
+ *
481
+ * @param {String} desc description of this specification
482
+ * @param {Function} func defines the preconditions and expectations of the spec
483
+ */
484
+ var xit = function(desc, func) {
485
+ return jasmine.getEnv().xit(desc, func);
486
+ };
487
+ if (isCommonJS) exports.xit = xit;
488
+
489
+ /**
490
+ * Starts a chain for a Jasmine expectation.
491
+ *
492
+ * It is passed an Object that is the actual value and should chain to one of the many
493
+ * jasmine.Matchers functions.
494
+ *
495
+ * @param {Object} actual Actual value to test against and expected value
496
+ */
497
+ var expect = function(actual) {
498
+ return jasmine.getEnv().currentSpec.expect(actual);
499
+ };
500
+ if (isCommonJS) exports.expect = expect;
501
+
502
+ /**
503
+ * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
504
+ *
505
+ * @param {Function} func Function that defines part of a jasmine spec.
506
+ */
507
+ var runs = function(func) {
508
+ jasmine.getEnv().currentSpec.runs(func);
509
+ };
510
+ if (isCommonJS) exports.runs = runs;
511
+
512
+ /**
513
+ * Waits a fixed time period before moving to the next block.
514
+ *
515
+ * @deprecated Use waitsFor() instead
516
+ * @param {Number} timeout milliseconds to wait
517
+ */
518
+ var waits = function(timeout) {
519
+ jasmine.getEnv().currentSpec.waits(timeout);
520
+ };
521
+ if (isCommonJS) exports.waits = waits;
522
+
523
+ /**
524
+ * Waits for the latchFunction to return true before proceeding to the next block.
525
+ *
526
+ * @param {Function} latchFunction
527
+ * @param {String} optional_timeoutMessage
528
+ * @param {Number} optional_timeout
529
+ */
530
+ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
531
+ jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
532
+ };
533
+ if (isCommonJS) exports.waitsFor = waitsFor;
534
+
535
+ /**
536
+ * A function that is called before each spec in a suite.
537
+ *
538
+ * Used for spec setup, including validating assumptions.
539
+ *
540
+ * @param {Function} beforeEachFunction
541
+ */
542
+ var beforeEach = function(beforeEachFunction) {
543
+ jasmine.getEnv().beforeEach(beforeEachFunction);
544
+ };
545
+ if (isCommonJS) exports.beforeEach = beforeEach;
546
+
547
+ /**
548
+ * A function that is called after each spec in a suite.
549
+ *
550
+ * Used for restoring any state that is hijacked during spec execution.
551
+ *
552
+ * @param {Function} afterEachFunction
553
+ */
554
+ var afterEach = function(afterEachFunction) {
555
+ jasmine.getEnv().afterEach(afterEachFunction);
556
+ };
557
+ if (isCommonJS) exports.afterEach = afterEach;
558
+
559
+ /**
560
+ * Defines a suite of specifications.
561
+ *
562
+ * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
563
+ * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
564
+ * of setup in some tests.
565
+ *
566
+ * @example
567
+ * // TODO: a simple suite
568
+ *
569
+ * // TODO: a simple suite with a nested describe block
570
+ *
571
+ * @param {String} description A string, usually the class under test.
572
+ * @param {Function} specDefinitions function that defines several specs.
573
+ */
574
+ var describe = function(description, specDefinitions) {
575
+ return jasmine.getEnv().describe(description, specDefinitions);
576
+ };
577
+ if (isCommonJS) exports.describe = describe;
578
+
579
+ /**
580
+ * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
581
+ *
582
+ * @param {String} description A string, usually the class under test.
583
+ * @param {Function} specDefinitions function that defines several specs.
584
+ */
585
+ var xdescribe = function(description, specDefinitions) {
586
+ return jasmine.getEnv().xdescribe(description, specDefinitions);
587
+ };
588
+ if (isCommonJS) exports.xdescribe = xdescribe;
589
+
590
+
591
+ // Provide the XMLHttpRequest class for IE 5.x-6.x:
592
+ jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
593
+ function tryIt(f) {
594
+ try {
595
+ return f();
596
+ } catch(e) {
597
+ }
598
+ return null;
599
+ }
600
+
601
+ var xhr = tryIt(function() {
602
+ return new ActiveXObject("Msxml2.XMLHTTP.6.0");
603
+ }) ||
604
+ tryIt(function() {
605
+ return new ActiveXObject("Msxml2.XMLHTTP.3.0");
606
+ }) ||
607
+ tryIt(function() {
608
+ return new ActiveXObject("Msxml2.XMLHTTP");
609
+ }) ||
610
+ tryIt(function() {
611
+ return new ActiveXObject("Microsoft.XMLHTTP");
612
+ });
613
+
614
+ if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
615
+
616
+ return xhr;
617
+ } : XMLHttpRequest;
618
+ /**
619
+ * @namespace
620
+ */
621
+ jasmine.util = {};
622
+
623
+ /**
624
+ * Declare that a child class inherit it's prototype from the parent class.
625
+ *
626
+ * @private
627
+ * @param {Function} childClass
628
+ * @param {Function} parentClass
629
+ */
630
+ jasmine.util.inherit = function(childClass, parentClass) {
631
+ /**
632
+ * @private
633
+ */
634
+ var subclass = function() {
635
+ };
636
+ subclass.prototype = parentClass.prototype;
637
+ childClass.prototype = new subclass();
638
+ };
639
+
640
+ jasmine.util.formatException = function(e) {
641
+ var lineNumber;
642
+ if (e.line) {
643
+ lineNumber = e.line;
644
+ }
645
+ else if (e.lineNumber) {
646
+ lineNumber = e.lineNumber;
647
+ }
648
+
649
+ var file;
650
+
651
+ if (e.sourceURL) {
652
+ file = e.sourceURL;
653
+ }
654
+ else if (e.fileName) {
655
+ file = e.fileName;
656
+ }
657
+
658
+ var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
659
+
660
+ if (file && lineNumber) {
661
+ message += ' in ' + file + ' (line ' + lineNumber + ')';
662
+ }
663
+
664
+ return message;
665
+ };
666
+
667
+ jasmine.util.htmlEscape = function(str) {
668
+ if (!str) return str;
669
+ return str.replace(/&/g, '&amp;')
670
+ .replace(/</g, '&lt;')
671
+ .replace(/>/g, '&gt;');
672
+ };
673
+
674
+ jasmine.util.argsToArray = function(args) {
675
+ var arrayOfArgs = [];
676
+ for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
677
+ return arrayOfArgs;
678
+ };
679
+
680
+ jasmine.util.extend = function(destination, source) {
681
+ for (var property in source) destination[property] = source[property];
682
+ return destination;
683
+ };
684
+
685
+ /**
686
+ * Environment for Jasmine
687
+ *
688
+ * @constructor
689
+ */
690
+ jasmine.Env = function() {
691
+ this.currentSpec = null;
692
+ this.currentSuite = null;
693
+ this.currentRunner_ = new jasmine.Runner(this);
694
+
695
+ this.reporter = new jasmine.MultiReporter();
696
+
697
+ this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
698
+ this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
699
+ this.lastUpdate = 0;
700
+ this.specFilter = function() {
701
+ return true;
702
+ };
703
+
704
+ this.nextSpecId_ = 0;
705
+ this.nextSuiteId_ = 0;
706
+ this.equalityTesters_ = [];
707
+
708
+ // wrap matchers
709
+ this.matchersClass = function() {
710
+ jasmine.Matchers.apply(this, arguments);
711
+ };
712
+ jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
713
+
714
+ jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
715
+ };
716
+
717
+
718
+ jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
719
+ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
720
+ jasmine.Env.prototype.setInterval = jasmine.setInterval;
721
+ jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
722
+
723
+ /**
724
+ * @returns an object containing jasmine version build info, if set.
725
+ */
726
+ jasmine.Env.prototype.version = function () {
727
+ if (jasmine.version_) {
728
+ return jasmine.version_;
729
+ } else {
730
+ throw new Error('Version not set');
731
+ }
732
+ };
733
+
734
+ /**
735
+ * @returns string containing jasmine version build info, if set.
736
+ */
737
+ jasmine.Env.prototype.versionString = function() {
738
+ if (jasmine.version_) {
739
+ var version = this.version();
740
+ return version.major + "." + version.minor + "." + version.build + " revision " + version.revision;
741
+ } else {
742
+ return "version unknown";
743
+ }
744
+ };
745
+
746
+ /**
747
+ * @returns a sequential integer starting at 0
748
+ */
749
+ jasmine.Env.prototype.nextSpecId = function () {
750
+ return this.nextSpecId_++;
751
+ };
752
+
753
+ /**
754
+ * @returns a sequential integer starting at 0
755
+ */
756
+ jasmine.Env.prototype.nextSuiteId = function () {
757
+ return this.nextSuiteId_++;
758
+ };
759
+
760
+ /**
761
+ * Register a reporter to receive status updates from Jasmine.
762
+ * @param {jasmine.Reporter} reporter An object which will receive status updates.
763
+ */
764
+ jasmine.Env.prototype.addReporter = function(reporter) {
765
+ this.reporter.addReporter(reporter);
766
+ };
767
+
768
+ jasmine.Env.prototype.execute = function() {
769
+ this.currentRunner_.execute();
770
+ };
771
+
772
+ jasmine.Env.prototype.describe = function(description, specDefinitions) {
773
+ var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
774
+
775
+ var parentSuite = this.currentSuite;
776
+ if (parentSuite) {
777
+ parentSuite.add(suite);
778
+ } else {
779
+ this.currentRunner_.add(suite);
780
+ }
781
+
782
+ this.currentSuite = suite;
783
+
784
+ var declarationError = null;
785
+ try {
786
+ specDefinitions.call(suite);
787
+ } catch(e) {
788
+ declarationError = e;
789
+ }
790
+
791
+ if (declarationError) {
792
+ this.it("encountered a declaration exception", function() {
793
+ throw declarationError;
794
+ });
795
+ }
796
+
797
+ this.currentSuite = parentSuite;
798
+
799
+ return suite;
800
+ };
801
+
802
+ jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
803
+ if (this.currentSuite) {
804
+ this.currentSuite.beforeEach(beforeEachFunction);
805
+ } else {
806
+ this.currentRunner_.beforeEach(beforeEachFunction);
807
+ }
808
+ };
809
+
810
+ jasmine.Env.prototype.currentRunner = function () {
811
+ return this.currentRunner_;
812
+ };
813
+
814
+ jasmine.Env.prototype.afterEach = function(afterEachFunction) {
815
+ if (this.currentSuite) {
816
+ this.currentSuite.afterEach(afterEachFunction);
817
+ } else {
818
+ this.currentRunner_.afterEach(afterEachFunction);
819
+ }
820
+
821
+ };
822
+
823
+ jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
824
+ return {
825
+ execute: function() {
826
+ }
827
+ };
828
+ };
829
+
830
+ jasmine.Env.prototype.it = function(description, func) {
831
+ var spec = new jasmine.Spec(this, this.currentSuite, description);
832
+ this.currentSuite.add(spec);
833
+ this.currentSpec = spec;
834
+
835
+ if (func) {
836
+ spec.runs(func);
837
+ }
838
+
839
+ return spec;
840
+ };
841
+
842
+ jasmine.Env.prototype.xit = function(desc, func) {
843
+ return {
844
+ id: this.nextSpecId(),
845
+ runs: function() {
846
+ }
847
+ };
848
+ };
849
+
850
+ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
851
+ if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
852
+ return true;
853
+ }
854
+
855
+ a.__Jasmine_been_here_before__ = b;
856
+ b.__Jasmine_been_here_before__ = a;
857
+
858
+ var hasKey = function(obj, keyName) {
859
+ return obj !== null && obj[keyName] !== jasmine.undefined;
860
+ };
861
+
862
+ for (var property in b) {
863
+ if (!hasKey(a, property) && hasKey(b, property)) {
864
+ mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
865
+ }
866
+ }
867
+ for (property in a) {
868
+ if (!hasKey(b, property) && hasKey(a, property)) {
869
+ mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
870
+ }
871
+ }
872
+ for (property in b) {
873
+ if (property == '__Jasmine_been_here_before__') continue;
874
+ if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
875
+ mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
876
+ }
877
+ }
878
+
879
+ if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
880
+ mismatchValues.push("arrays were not the same length");
881
+ }
882
+
883
+ delete a.__Jasmine_been_here_before__;
884
+ delete b.__Jasmine_been_here_before__;
885
+ return (mismatchKeys.length === 0 && mismatchValues.length === 0);
886
+ };
887
+
888
+ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
889
+ mismatchKeys = mismatchKeys || [];
890
+ mismatchValues = mismatchValues || [];
891
+
892
+ for (var i = 0; i < this.equalityTesters_.length; i++) {
893
+ var equalityTester = this.equalityTesters_[i];
894
+ var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
895
+ if (result !== jasmine.undefined) return result;
896
+ }
897
+
898
+ if (a === b) return true;
899
+
900
+ if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
901
+ return (a == jasmine.undefined && b == jasmine.undefined);
902
+ }
903
+
904
+ if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
905
+ return a === b;
906
+ }
907
+
908
+ if (a instanceof Date && b instanceof Date) {
909
+ return a.getTime() == b.getTime();
910
+ }
911
+
912
+ if (a instanceof jasmine.Matchers.Any) {
913
+ return a.matches(b);
914
+ }
915
+
916
+ if (b instanceof jasmine.Matchers.Any) {
917
+ return b.matches(a);
918
+ }
919
+
920
+ if (jasmine.isString_(a) && jasmine.isString_(b)) {
921
+ return (a == b);
922
+ }
923
+
924
+ if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
925
+ return (a == b);
926
+ }
927
+
928
+ if (typeof a === "object" && typeof b === "object") {
929
+ return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
930
+ }
931
+
932
+ //Straight check
933
+ return (a === b);
934
+ };
935
+
936
+ jasmine.Env.prototype.contains_ = function(haystack, needle) {
937
+ if (jasmine.isArray_(haystack)) {
938
+ for (var i = 0; i < haystack.length; i++) {
939
+ if (this.equals_(haystack[i], needle)) return true;
940
+ }
941
+ return false;
942
+ }
943
+ return haystack.indexOf(needle) >= 0;
944
+ };
945
+
946
+ jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
947
+ this.equalityTesters_.push(equalityTester);
948
+ };
949
+ /** No-op base class for Jasmine reporters.
950
+ *
951
+ * @constructor
952
+ */
953
+ jasmine.Reporter = function() {
954
+ };
955
+
956
+ //noinspection JSUnusedLocalSymbols
957
+ jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
958
+ };
959
+
960
+ //noinspection JSUnusedLocalSymbols
961
+ jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
962
+ };
963
+
964
+ //noinspection JSUnusedLocalSymbols
965
+ jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
966
+ };
967
+
968
+ //noinspection JSUnusedLocalSymbols
969
+ jasmine.Reporter.prototype.reportSpecStarting = function(spec) {
970
+ };
971
+
972
+ //noinspection JSUnusedLocalSymbols
973
+ jasmine.Reporter.prototype.reportSpecResults = function(spec) {
974
+ };
975
+
976
+ //noinspection JSUnusedLocalSymbols
977
+ jasmine.Reporter.prototype.log = function(str) {
978
+ };
979
+
980
+ /**
981
+ * Blocks are functions with executable code that make up a spec.
982
+ *
983
+ * @constructor
984
+ * @param {jasmine.Env} env
985
+ * @param {Function} func
986
+ * @param {jasmine.Spec} spec
987
+ */
988
+ jasmine.Block = function(env, func, spec) {
989
+ this.env = env;
990
+ this.func = func;
991
+ this.spec = spec;
992
+ };
993
+
994
+ jasmine.Block.prototype.execute = function(onComplete) {
995
+ try {
996
+ this.func.apply(this.spec);
997
+ } catch (e) {
998
+ this.spec.fail(e);
999
+ }
1000
+ onComplete();
1001
+ };
1002
+ /** JavaScript API reporter.
1003
+ *
1004
+ * @constructor
1005
+ */
1006
+ jasmine.JsApiReporter = function() {
1007
+ this.started = false;
1008
+ this.finished = false;
1009
+ this.suites_ = [];
1010
+ this.results_ = {};
1011
+ };
1012
+
1013
+ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
1014
+ this.started = true;
1015
+ var suites = runner.topLevelSuites();
1016
+ for (var i = 0; i < suites.length; i++) {
1017
+ var suite = suites[i];
1018
+ this.suites_.push(this.summarize_(suite));
1019
+ }
1020
+ };
1021
+
1022
+ jasmine.JsApiReporter.prototype.suites = function() {
1023
+ return this.suites_;
1024
+ };
1025
+
1026
+ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
1027
+ var isSuite = suiteOrSpec instanceof jasmine.Suite;
1028
+ var summary = {
1029
+ id: suiteOrSpec.id,
1030
+ name: suiteOrSpec.description,
1031
+ type: isSuite ? 'suite' : 'spec',
1032
+ children: []
1033
+ };
1034
+
1035
+ if (isSuite) {
1036
+ var children = suiteOrSpec.children();
1037
+ for (var i = 0; i < children.length; i++) {
1038
+ summary.children.push(this.summarize_(children[i]));
1039
+ }
1040
+ }
1041
+ return summary;
1042
+ };
1043
+
1044
+ jasmine.JsApiReporter.prototype.results = function() {
1045
+ return this.results_;
1046
+ };
1047
+
1048
+ jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
1049
+ return this.results_[specId];
1050
+ };
1051
+
1052
+ //noinspection JSUnusedLocalSymbols
1053
+ jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
1054
+ this.finished = true;
1055
+ };
1056
+
1057
+ //noinspection JSUnusedLocalSymbols
1058
+ jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
1059
+ };
1060
+
1061
+ //noinspection JSUnusedLocalSymbols
1062
+ jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
1063
+ this.results_[spec.id] = {
1064
+ messages: spec.results().getItems(),
1065
+ result: spec.results().failedCount > 0 ? "failed" : "passed"
1066
+ };
1067
+ };
1068
+
1069
+ //noinspection JSUnusedLocalSymbols
1070
+ jasmine.JsApiReporter.prototype.log = function(str) {
1071
+ };
1072
+
1073
+ jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
1074
+ var results = {};
1075
+ for (var i = 0; i < specIds.length; i++) {
1076
+ var specId = specIds[i];
1077
+ results[specId] = this.summarizeResult_(this.results_[specId]);
1078
+ }
1079
+ return results;
1080
+ };
1081
+
1082
+ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
1083
+ var summaryMessages = [];
1084
+ var messagesLength = result.messages.length;
1085
+ for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
1086
+ var resultMessage = result.messages[messageIndex];
1087
+ summaryMessages.push({
1088
+ text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined,
1089
+ passed: resultMessage.passed ? resultMessage.passed() : true,
1090
+ type: resultMessage.type,
1091
+ message: resultMessage.message,
1092
+ trace: {
1093
+ stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
1094
+ }
1095
+ });
1096
+ }
1097
+
1098
+ return {
1099
+ result : result.result,
1100
+ messages : summaryMessages
1101
+ };
1102
+ };
1103
+
1104
+ /**
1105
+ * @constructor
1106
+ * @param {jasmine.Env} env
1107
+ * @param actual
1108
+ * @param {jasmine.Spec} spec
1109
+ */
1110
+ jasmine.Matchers = function(env, actual, spec, opt_isNot) {
1111
+ this.env = env;
1112
+ this.actual = actual;
1113
+ this.spec = spec;
1114
+ this.isNot = opt_isNot || false;
1115
+ this.reportWasCalled_ = false;
1116
+ };
1117
+
1118
+ // todo: @deprecated as of Jasmine 0.11, remove soon [xw]
1119
+ jasmine.Matchers.pp = function(str) {
1120
+ throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
1121
+ };
1122
+
1123
+ // todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw]
1124
+ jasmine.Matchers.prototype.report = function(result, failing_message, details) {
1125
+ throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs");
1126
+ };
1127
+
1128
+ jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
1129
+ for (var methodName in prototype) {
1130
+ if (methodName == 'report') continue;
1131
+ var orig = prototype[methodName];
1132
+ matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);
1133
+ }
1134
+ };
1135
+
1136
+ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
1137
+ return function() {
1138
+ var matcherArgs = jasmine.util.argsToArray(arguments);
1139
+ var result = matcherFunction.apply(this, arguments);
1140
+
1141
+ if (this.isNot) {
1142
+ result = !result;
1143
+ }
1144
+
1145
+ if (this.reportWasCalled_) return result;
1146
+
1147
+ var message;
1148
+ if (!result) {
1149
+ if (this.message) {
1150
+ message = this.message.apply(this, arguments);
1151
+ if (jasmine.isArray_(message)) {
1152
+ message = message[this.isNot ? 1 : 0];
1153
+ }
1154
+ } else {
1155
+ var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
1156
+ message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
1157
+ if (matcherArgs.length > 0) {
1158
+ for (var i = 0; i < matcherArgs.length; i++) {
1159
+ if (i > 0) message += ",";
1160
+ message += " " + jasmine.pp(matcherArgs[i]);
1161
+ }
1162
+ }
1163
+ message += ".";
1164
+ }
1165
+ }
1166
+ var expectationResult = new jasmine.ExpectationResult({
1167
+ matcherName: matcherName,
1168
+ passed: result,
1169
+ expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
1170
+ actual: this.actual,
1171
+ message: message
1172
+ });
1173
+ this.spec.addMatcherResult(expectationResult);
1174
+ return jasmine.undefined;
1175
+ };
1176
+ };
1177
+
1178
+
1179
+
1180
+
1181
+ /**
1182
+ * toBe: compares the actual to the expected using ===
1183
+ * @param expected
1184
+ */
1185
+ jasmine.Matchers.prototype.toBe = function(expected) {
1186
+ return this.actual === expected;
1187
+ };
1188
+
1189
+ /**
1190
+ * toNotBe: compares the actual to the expected using !==
1191
+ * @param expected
1192
+ * @deprecated as of 1.0. Use not.toBe() instead.
1193
+ */
1194
+ jasmine.Matchers.prototype.toNotBe = function(expected) {
1195
+ return this.actual !== expected;
1196
+ };
1197
+
1198
+ /**
1199
+ * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc.
1200
+ *
1201
+ * @param expected
1202
+ */
1203
+ jasmine.Matchers.prototype.toEqual = function(expected) {
1204
+ return this.env.equals_(this.actual, expected);
1205
+ };
1206
+
1207
+ /**
1208
+ * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
1209
+ * @param expected
1210
+ * @deprecated as of 1.0. Use not.toNotEqual() instead.
1211
+ */
1212
+ jasmine.Matchers.prototype.toNotEqual = function(expected) {
1213
+ return !this.env.equals_(this.actual, expected);
1214
+ };
1215
+
1216
+ /**
1217
+ * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes
1218
+ * a pattern or a String.
1219
+ *
1220
+ * @param expected
1221
+ */
1222
+ jasmine.Matchers.prototype.toMatch = function(expected) {
1223
+ return new RegExp(expected).test(this.actual);
1224
+ };
1225
+
1226
+ /**
1227
+ * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
1228
+ * @param expected
1229
+ * @deprecated as of 1.0. Use not.toMatch() instead.
1230
+ */
1231
+ jasmine.Matchers.prototype.toNotMatch = function(expected) {
1232
+ return !(new RegExp(expected).test(this.actual));
1233
+ };
1234
+
1235
+ /**
1236
+ * Matcher that compares the actual to jasmine.undefined.
1237
+ */
1238
+ jasmine.Matchers.prototype.toBeDefined = function() {
1239
+ return (this.actual !== jasmine.undefined);
1240
+ };
1241
+
1242
+ /**
1243
+ * Matcher that compares the actual to jasmine.undefined.
1244
+ */
1245
+ jasmine.Matchers.prototype.toBeUndefined = function() {
1246
+ return (this.actual === jasmine.undefined);
1247
+ };
1248
+
1249
+ /**
1250
+ * Matcher that compares the actual to null.
1251
+ */
1252
+ jasmine.Matchers.prototype.toBeNull = function() {
1253
+ return (this.actual === null);
1254
+ };
1255
+
1256
+ /**
1257
+ * Matcher that boolean not-nots the actual.
1258
+ */
1259
+ jasmine.Matchers.prototype.toBeTruthy = function() {
1260
+ return !!this.actual;
1261
+ };
1262
+
1263
+
1264
+ /**
1265
+ * Matcher that boolean nots the actual.
1266
+ */
1267
+ jasmine.Matchers.prototype.toBeFalsy = function() {
1268
+ return !this.actual;
1269
+ };
1270
+
1271
+
1272
+ /**
1273
+ * Matcher that checks to see if the actual, a Jasmine spy, was called.
1274
+ */
1275
+ jasmine.Matchers.prototype.toHaveBeenCalled = function() {
1276
+ if (arguments.length > 0) {
1277
+ throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
1278
+ }
1279
+
1280
+ if (!jasmine.isSpy(this.actual)) {
1281
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1282
+ }
1283
+
1284
+ this.message = function() {
1285
+ return [
1286
+ "Expected spy " + this.actual.identity + " to have been called.",
1287
+ "Expected spy " + this.actual.identity + " not to have been called."
1288
+ ];
1289
+ };
1290
+
1291
+ return this.actual.wasCalled;
1292
+ };
1293
+
1294
+ /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
1295
+ jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
1296
+
1297
+ /**
1298
+ * Matcher that checks to see if the actual, a Jasmine spy, was not called.
1299
+ *
1300
+ * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
1301
+ */
1302
+ jasmine.Matchers.prototype.wasNotCalled = function() {
1303
+ if (arguments.length > 0) {
1304
+ throw new Error('wasNotCalled does not take arguments');
1305
+ }
1306
+
1307
+ if (!jasmine.isSpy(this.actual)) {
1308
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1309
+ }
1310
+
1311
+ this.message = function() {
1312
+ return [
1313
+ "Expected spy " + this.actual.identity + " to not have been called.",
1314
+ "Expected spy " + this.actual.identity + " to have been called."
1315
+ ];
1316
+ };
1317
+
1318
+ return !this.actual.wasCalled;
1319
+ };
1320
+
1321
+ /**
1322
+ * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
1323
+ *
1324
+ * @example
1325
+ *
1326
+ */
1327
+ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
1328
+ var expectedArgs = jasmine.util.argsToArray(arguments);
1329
+ if (!jasmine.isSpy(this.actual)) {
1330
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1331
+ }
1332
+ this.message = function() {
1333
+ if (this.actual.callCount === 0) {
1334
+ // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
1335
+ return [
1336
+ "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
1337
+ "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
1338
+ ];
1339
+ } else {
1340
+ return [
1341
+ "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
1342
+ "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
1343
+ ];
1344
+ }
1345
+ };
1346
+
1347
+ return this.env.contains_(this.actual.argsForCall, expectedArgs);
1348
+ };
1349
+
1350
+ /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
1351
+ jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
1352
+
1353
+ /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
1354
+ jasmine.Matchers.prototype.wasNotCalledWith = function() {
1355
+ var expectedArgs = jasmine.util.argsToArray(arguments);
1356
+ if (!jasmine.isSpy(this.actual)) {
1357
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1358
+ }
1359
+
1360
+ this.message = function() {
1361
+ return [
1362
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
1363
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
1364
+ ];
1365
+ };
1366
+
1367
+ return !this.env.contains_(this.actual.argsForCall, expectedArgs);
1368
+ };
1369
+
1370
+ /**
1371
+ * Matcher that checks that the expected item is an element in the actual Array.
1372
+ *
1373
+ * @param {Object} expected
1374
+ */
1375
+ jasmine.Matchers.prototype.toContain = function(expected) {
1376
+ return this.env.contains_(this.actual, expected);
1377
+ };
1378
+
1379
+ /**
1380
+ * Matcher that checks that the expected item is NOT an element in the actual Array.
1381
+ *
1382
+ * @param {Object} expected
1383
+ * @deprecated as of 1.0. Use not.toNotContain() instead.
1384
+ */
1385
+ jasmine.Matchers.prototype.toNotContain = function(expected) {
1386
+ return !this.env.contains_(this.actual, expected);
1387
+ };
1388
+
1389
+ jasmine.Matchers.prototype.toBeLessThan = function(expected) {
1390
+ return this.actual < expected;
1391
+ };
1392
+
1393
+ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
1394
+ return this.actual > expected;
1395
+ };
1396
+
1397
+ /**
1398
+ * Matcher that checks that the expected item is equal to the actual item
1399
+ * up to a given level of decimal precision (default 2).
1400
+ *
1401
+ * @param {Number} expected
1402
+ * @param {Number} precision
1403
+ */
1404
+ jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
1405
+ if (!(precision === 0)) {
1406
+ precision = precision || 2;
1407
+ }
1408
+ var multiplier = Math.pow(10, precision);
1409
+ var actual = Math.round(this.actual * multiplier);
1410
+ expected = Math.round(expected * multiplier);
1411
+ return expected == actual;
1412
+ };
1413
+
1414
+ /**
1415
+ * Matcher that checks that the expected exception was thrown by the actual.
1416
+ *
1417
+ * @param {String} expected
1418
+ */
1419
+ jasmine.Matchers.prototype.toThrow = function(expected) {
1420
+ var result = false;
1421
+ var exception;
1422
+ if (typeof this.actual != 'function') {
1423
+ throw new Error('Actual is not a function');
1424
+ }
1425
+ try {
1426
+ this.actual();
1427
+ } catch (e) {
1428
+ exception = e;
1429
+ }
1430
+ if (exception) {
1431
+ result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
1432
+ }
1433
+
1434
+ var not = this.isNot ? "not " : "";
1435
+
1436
+ this.message = function() {
1437
+ if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
1438
+ return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
1439
+ } else {
1440
+ return "Expected function to throw an exception.";
1441
+ }
1442
+ };
1443
+
1444
+ return result;
1445
+ };
1446
+
1447
+ jasmine.Matchers.Any = function(expectedClass) {
1448
+ this.expectedClass = expectedClass;
1449
+ };
1450
+
1451
+ jasmine.Matchers.Any.prototype.matches = function(other) {
1452
+ if (this.expectedClass == String) {
1453
+ return typeof other == 'string' || other instanceof String;
1454
+ }
1455
+
1456
+ if (this.expectedClass == Number) {
1457
+ return typeof other == 'number' || other instanceof Number;
1458
+ }
1459
+
1460
+ if (this.expectedClass == Function) {
1461
+ return typeof other == 'function' || other instanceof Function;
1462
+ }
1463
+
1464
+ if (this.expectedClass == Object) {
1465
+ return typeof other == 'object';
1466
+ }
1467
+
1468
+ return other instanceof this.expectedClass;
1469
+ };
1470
+
1471
+ jasmine.Matchers.Any.prototype.toString = function() {
1472
+ return '<jasmine.any(' + this.expectedClass + ')>';
1473
+ };
1474
+
1475
+ /**
1476
+ * @constructor
1477
+ */
1478
+ jasmine.MultiReporter = function() {
1479
+ this.subReporters_ = [];
1480
+ };
1481
+ jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
1482
+
1483
+ jasmine.MultiReporter.prototype.addReporter = function(reporter) {
1484
+ this.subReporters_.push(reporter);
1485
+ };
1486
+
1487
+ (function() {
1488
+ var functionNames = [
1489
+ "reportRunnerStarting",
1490
+ "reportRunnerResults",
1491
+ "reportSuiteResults",
1492
+ "reportSpecStarting",
1493
+ "reportSpecResults",
1494
+ "log"
1495
+ ];
1496
+ for (var i = 0; i < functionNames.length; i++) {
1497
+ var functionName = functionNames[i];
1498
+ jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
1499
+ return function() {
1500
+ for (var j = 0; j < this.subReporters_.length; j++) {
1501
+ var subReporter = this.subReporters_[j];
1502
+ if (subReporter[functionName]) {
1503
+ subReporter[functionName].apply(subReporter, arguments);
1504
+ }
1505
+ }
1506
+ };
1507
+ })(functionName);
1508
+ }
1509
+ })();
1510
+ /**
1511
+ * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
1512
+ *
1513
+ * @constructor
1514
+ */
1515
+ jasmine.NestedResults = function() {
1516
+ /**
1517
+ * The total count of results
1518
+ */
1519
+ this.totalCount = 0;
1520
+ /**
1521
+ * Number of passed results
1522
+ */
1523
+ this.passedCount = 0;
1524
+ /**
1525
+ * Number of failed results
1526
+ */
1527
+ this.failedCount = 0;
1528
+ /**
1529
+ * Was this suite/spec skipped?
1530
+ */
1531
+ this.skipped = false;
1532
+ /**
1533
+ * @ignore
1534
+ */
1535
+ this.items_ = [];
1536
+ };
1537
+
1538
+ /**
1539
+ * Roll up the result counts.
1540
+ *
1541
+ * @param result
1542
+ */
1543
+ jasmine.NestedResults.prototype.rollupCounts = function(result) {
1544
+ this.totalCount += result.totalCount;
1545
+ this.passedCount += result.passedCount;
1546
+ this.failedCount += result.failedCount;
1547
+ };
1548
+
1549
+ /**
1550
+ * Adds a log message.
1551
+ * @param values Array of message parts which will be concatenated later.
1552
+ */
1553
+ jasmine.NestedResults.prototype.log = function(values) {
1554
+ this.items_.push(new jasmine.MessageResult(values));
1555
+ };
1556
+
1557
+ /**
1558
+ * Getter for the results: message & results.
1559
+ */
1560
+ jasmine.NestedResults.prototype.getItems = function() {
1561
+ return this.items_;
1562
+ };
1563
+
1564
+ /**
1565
+ * Adds a result, tracking counts (total, passed, & failed)
1566
+ * @param {jasmine.ExpectationResult|jasmine.NestedResults} result
1567
+ */
1568
+ jasmine.NestedResults.prototype.addResult = function(result) {
1569
+ if (result.type != 'log') {
1570
+ if (result.items_) {
1571
+ this.rollupCounts(result);
1572
+ } else {
1573
+ this.totalCount++;
1574
+ if (result.passed()) {
1575
+ this.passedCount++;
1576
+ } else {
1577
+ this.failedCount++;
1578
+ }
1579
+ }
1580
+ }
1581
+ this.items_.push(result);
1582
+ };
1583
+
1584
+ /**
1585
+ * @returns {Boolean} True if <b>everything</b> below passed
1586
+ */
1587
+ jasmine.NestedResults.prototype.passed = function() {
1588
+ return this.passedCount === this.totalCount;
1589
+ };
1590
+ /**
1591
+ * Base class for pretty printing for expectation results.
1592
+ */
1593
+ jasmine.PrettyPrinter = function() {
1594
+ this.ppNestLevel_ = 0;
1595
+ };
1596
+
1597
+ /**
1598
+ * Formats a value in a nice, human-readable string.
1599
+ *
1600
+ * @param value
1601
+ */
1602
+ jasmine.PrettyPrinter.prototype.format = function(value) {
1603
+ if (this.ppNestLevel_ > 40) {
1604
+ throw new Error('jasmine.PrettyPrinter: format() nested too deeply!');
1605
+ }
1606
+
1607
+ this.ppNestLevel_++;
1608
+ try {
1609
+ if (value === jasmine.undefined) {
1610
+ this.emitScalar('undefined');
1611
+ } else if (value === null) {
1612
+ this.emitScalar('null');
1613
+ } else if (value === jasmine.getGlobal()) {
1614
+ this.emitScalar('<global>');
1615
+ } else if (value instanceof jasmine.Matchers.Any) {
1616
+ this.emitScalar(value.toString());
1617
+ } else if (typeof value === 'string') {
1618
+ this.emitString(value);
1619
+ } else if (jasmine.isSpy(value)) {
1620
+ this.emitScalar("spy on " + value.identity);
1621
+ } else if (value instanceof RegExp) {
1622
+ this.emitScalar(value.toString());
1623
+ } else if (typeof value === 'function') {
1624
+ this.emitScalar('Function');
1625
+ } else if (typeof value.nodeType === 'number') {
1626
+ this.emitScalar('HTMLNode');
1627
+ } else if (value instanceof Date) {
1628
+ this.emitScalar('Date(' + value + ')');
1629
+ } else if (value.__Jasmine_been_here_before__) {
1630
+ this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
1631
+ } else if (jasmine.isArray_(value) || typeof value == 'object') {
1632
+ value.__Jasmine_been_here_before__ = true;
1633
+ if (jasmine.isArray_(value)) {
1634
+ this.emitArray(value);
1635
+ } else {
1636
+ this.emitObject(value);
1637
+ }
1638
+ delete value.__Jasmine_been_here_before__;
1639
+ } else {
1640
+ this.emitScalar(value.toString());
1641
+ }
1642
+ } finally {
1643
+ this.ppNestLevel_--;
1644
+ }
1645
+ };
1646
+
1647
+ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
1648
+ for (var property in obj) {
1649
+ if (property == '__Jasmine_been_here_before__') continue;
1650
+ fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
1651
+ obj.__lookupGetter__(property) !== null) : false);
1652
+ }
1653
+ };
1654
+
1655
+ jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
1656
+ jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
1657
+ jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
1658
+ jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
1659
+
1660
+ jasmine.StringPrettyPrinter = function() {
1661
+ jasmine.PrettyPrinter.call(this);
1662
+
1663
+ this.string = '';
1664
+ };
1665
+ jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter);
1666
+
1667
+ jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
1668
+ this.append(value);
1669
+ };
1670
+
1671
+ jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
1672
+ this.append("'" + value + "'");
1673
+ };
1674
+
1675
+ jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
1676
+ this.append('[ ');
1677
+ for (var i = 0; i < array.length; i++) {
1678
+ if (i > 0) {
1679
+ this.append(', ');
1680
+ }
1681
+ this.format(array[i]);
1682
+ }
1683
+ this.append(' ]');
1684
+ };
1685
+
1686
+ jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) {
1687
+ var self = this;
1688
+ this.append('{ ');
1689
+ var first = true;
1690
+
1691
+ this.iterateObject(obj, function(property, isGetter) {
1692
+ if (first) {
1693
+ first = false;
1694
+ } else {
1695
+ self.append(', ');
1696
+ }
1697
+
1698
+ self.append(property);
1699
+ self.append(' : ');
1700
+ if (isGetter) {
1701
+ self.append('<getter>');
1702
+ } else {
1703
+ self.format(obj[property]);
1704
+ }
1705
+ });
1706
+
1707
+ this.append(' }');
1708
+ };
1709
+
1710
+ jasmine.StringPrettyPrinter.prototype.append = function(value) {
1711
+ this.string += value;
1712
+ };
1713
+ jasmine.Queue = function(env) {
1714
+ this.env = env;
1715
+ this.blocks = [];
1716
+ this.running = false;
1717
+ this.index = 0;
1718
+ this.offset = 0;
1719
+ this.abort = false;
1720
+ };
1721
+
1722
+ jasmine.Queue.prototype.addBefore = function(block) {
1723
+ this.blocks.unshift(block);
1724
+ };
1725
+
1726
+ jasmine.Queue.prototype.add = function(block) {
1727
+ this.blocks.push(block);
1728
+ };
1729
+
1730
+ jasmine.Queue.prototype.insertNext = function(block) {
1731
+ this.blocks.splice((this.index + this.offset + 1), 0, block);
1732
+ this.offset++;
1733
+ };
1734
+
1735
+ jasmine.Queue.prototype.start = function(onComplete) {
1736
+ this.running = true;
1737
+ this.onComplete = onComplete;
1738
+ this.next_();
1739
+ };
1740
+
1741
+ jasmine.Queue.prototype.isRunning = function() {
1742
+ return this.running;
1743
+ };
1744
+
1745
+ jasmine.Queue.LOOP_DONT_RECURSE = true;
1746
+
1747
+ jasmine.Queue.prototype.next_ = function() {
1748
+ var self = this;
1749
+ var goAgain = true;
1750
+
1751
+ while (goAgain) {
1752
+ goAgain = false;
1753
+
1754
+ if (self.index < self.blocks.length && !this.abort) {
1755
+ var calledSynchronously = true;
1756
+ var completedSynchronously = false;
1757
+
1758
+ var onComplete = function () {
1759
+ if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
1760
+ completedSynchronously = true;
1761
+ return;
1762
+ }
1763
+
1764
+ if (self.blocks[self.index].abort) {
1765
+ self.abort = true;
1766
+ }
1767
+
1768
+ self.offset = 0;
1769
+ self.index++;
1770
+
1771
+ var now = new Date().getTime();
1772
+ if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
1773
+ self.env.lastUpdate = now;
1774
+ self.env.setTimeout(function() {
1775
+ self.next_();
1776
+ }, 0);
1777
+ } else {
1778
+ if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
1779
+ goAgain = true;
1780
+ } else {
1781
+ self.next_();
1782
+ }
1783
+ }
1784
+ };
1785
+ self.blocks[self.index].execute(onComplete);
1786
+
1787
+ calledSynchronously = false;
1788
+ if (completedSynchronously) {
1789
+ onComplete();
1790
+ }
1791
+
1792
+ } else {
1793
+ self.running = false;
1794
+ if (self.onComplete) {
1795
+ self.onComplete();
1796
+ }
1797
+ }
1798
+ }
1799
+ };
1800
+
1801
+ jasmine.Queue.prototype.results = function() {
1802
+ var results = new jasmine.NestedResults();
1803
+ for (var i = 0; i < this.blocks.length; i++) {
1804
+ if (this.blocks[i].results) {
1805
+ results.addResult(this.blocks[i].results());
1806
+ }
1807
+ }
1808
+ return results;
1809
+ };
1810
+
1811
+
1812
+ /**
1813
+ * Runner
1814
+ *
1815
+ * @constructor
1816
+ * @param {jasmine.Env} env
1817
+ */
1818
+ jasmine.Runner = function(env) {
1819
+ var self = this;
1820
+ self.env = env;
1821
+ self.queue = new jasmine.Queue(env);
1822
+ self.before_ = [];
1823
+ self.after_ = [];
1824
+ self.suites_ = [];
1825
+ };
1826
+
1827
+ jasmine.Runner.prototype.execute = function() {
1828
+ var self = this;
1829
+ if (self.env.reporter.reportRunnerStarting) {
1830
+ self.env.reporter.reportRunnerStarting(this);
1831
+ }
1832
+ self.queue.start(function () {
1833
+ self.finishCallback();
1834
+ });
1835
+ };
1836
+
1837
+ jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
1838
+ beforeEachFunction.typeName = 'beforeEach';
1839
+ this.before_.splice(0,0,beforeEachFunction);
1840
+ };
1841
+
1842
+ jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
1843
+ afterEachFunction.typeName = 'afterEach';
1844
+ this.after_.splice(0,0,afterEachFunction);
1845
+ };
1846
+
1847
+
1848
+ jasmine.Runner.prototype.finishCallback = function() {
1849
+ this.env.reporter.reportRunnerResults(this);
1850
+ };
1851
+
1852
+ jasmine.Runner.prototype.addSuite = function(suite) {
1853
+ this.suites_.push(suite);
1854
+ };
1855
+
1856
+ jasmine.Runner.prototype.add = function(block) {
1857
+ if (block instanceof jasmine.Suite) {
1858
+ this.addSuite(block);
1859
+ }
1860
+ this.queue.add(block);
1861
+ };
1862
+
1863
+ jasmine.Runner.prototype.specs = function () {
1864
+ var suites = this.suites();
1865
+ var specs = [];
1866
+ for (var i = 0; i < suites.length; i++) {
1867
+ specs = specs.concat(suites[i].specs());
1868
+ }
1869
+ return specs;
1870
+ };
1871
+
1872
+ jasmine.Runner.prototype.suites = function() {
1873
+ return this.suites_;
1874
+ };
1875
+
1876
+ jasmine.Runner.prototype.topLevelSuites = function() {
1877
+ var topLevelSuites = [];
1878
+ for (var i = 0; i < this.suites_.length; i++) {
1879
+ if (!this.suites_[i].parentSuite) {
1880
+ topLevelSuites.push(this.suites_[i]);
1881
+ }
1882
+ }
1883
+ return topLevelSuites;
1884
+ };
1885
+
1886
+ jasmine.Runner.prototype.results = function() {
1887
+ return this.queue.results();
1888
+ };
1889
+ /**
1890
+ * Internal representation of a Jasmine specification, or test.
1891
+ *
1892
+ * @constructor
1893
+ * @param {jasmine.Env} env
1894
+ * @param {jasmine.Suite} suite
1895
+ * @param {String} description
1896
+ */
1897
+ jasmine.Spec = function(env, suite, description) {
1898
+ if (!env) {
1899
+ throw new Error('jasmine.Env() required');
1900
+ }
1901
+ if (!suite) {
1902
+ throw new Error('jasmine.Suite() required');
1903
+ }
1904
+ var spec = this;
1905
+ spec.id = env.nextSpecId ? env.nextSpecId() : null;
1906
+ spec.env = env;
1907
+ spec.suite = suite;
1908
+ spec.description = description;
1909
+ spec.queue = new jasmine.Queue(env);
1910
+
1911
+ spec.afterCallbacks = [];
1912
+ spec.spies_ = [];
1913
+
1914
+ spec.results_ = new jasmine.NestedResults();
1915
+ spec.results_.description = description;
1916
+ spec.matchersClass = null;
1917
+ };
1918
+
1919
+ jasmine.Spec.prototype.getFullName = function() {
1920
+ return this.suite.getFullName() + ' ' + this.description + '.';
1921
+ };
1922
+
1923
+
1924
+ jasmine.Spec.prototype.results = function() {
1925
+ return this.results_;
1926
+ };
1927
+
1928
+ /**
1929
+ * All parameters are pretty-printed and concatenated together, then written to the spec's output.
1930
+ *
1931
+ * Be careful not to leave calls to <code>jasmine.log</code> in production code.
1932
+ */
1933
+ jasmine.Spec.prototype.log = function() {
1934
+ return this.results_.log(arguments);
1935
+ };
1936
+
1937
+ jasmine.Spec.prototype.runs = function (func) {
1938
+ var block = new jasmine.Block(this.env, func, this);
1939
+ this.addToQueue(block);
1940
+ return this;
1941
+ };
1942
+
1943
+ jasmine.Spec.prototype.addToQueue = function (block) {
1944
+ if (this.queue.isRunning()) {
1945
+ this.queue.insertNext(block);
1946
+ } else {
1947
+ this.queue.add(block);
1948
+ }
1949
+ };
1950
+
1951
+ /**
1952
+ * @param {jasmine.ExpectationResult} result
1953
+ */
1954
+ jasmine.Spec.prototype.addMatcherResult = function(result) {
1955
+ this.results_.addResult(result);
1956
+ };
1957
+
1958
+ jasmine.Spec.prototype.expect = function(actual) {
1959
+ var positive = new (this.getMatchersClass_())(this.env, actual, this);
1960
+ positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
1961
+ return positive;
1962
+ };
1963
+
1964
+ /**
1965
+ * Waits a fixed time period before moving to the next block.
1966
+ *
1967
+ * @deprecated Use waitsFor() instead
1968
+ * @param {Number} timeout milliseconds to wait
1969
+ */
1970
+ jasmine.Spec.prototype.waits = function(timeout) {
1971
+ var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
1972
+ this.addToQueue(waitsFunc);
1973
+ return this;
1974
+ };
1975
+
1976
+ /**
1977
+ * Waits for the latchFunction to return true before proceeding to the next block.
1978
+ *
1979
+ * @param {Function} latchFunction
1980
+ * @param {String} optional_timeoutMessage
1981
+ * @param {Number} optional_timeout
1982
+ */
1983
+ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
1984
+ var latchFunction_ = null;
1985
+ var optional_timeoutMessage_ = null;
1986
+ var optional_timeout_ = null;
1987
+
1988
+ for (var i = 0; i < arguments.length; i++) {
1989
+ var arg = arguments[i];
1990
+ switch (typeof arg) {
1991
+ case 'function':
1992
+ latchFunction_ = arg;
1993
+ break;
1994
+ case 'string':
1995
+ optional_timeoutMessage_ = arg;
1996
+ break;
1997
+ case 'number':
1998
+ optional_timeout_ = arg;
1999
+ break;
2000
+ }
2001
+ }
2002
+
2003
+ var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
2004
+ this.addToQueue(waitsForFunc);
2005
+ return this;
2006
+ };
2007
+
2008
+ jasmine.Spec.prototype.fail = function (e) {
2009
+ var expectationResult = new jasmine.ExpectationResult({
2010
+ passed: false,
2011
+ message: e ? jasmine.util.formatException(e) : 'Exception',
2012
+ trace: { stack: e.stack }
2013
+ });
2014
+ this.results_.addResult(expectationResult);
2015
+ };
2016
+
2017
+ jasmine.Spec.prototype.getMatchersClass_ = function() {
2018
+ return this.matchersClass || this.env.matchersClass;
2019
+ };
2020
+
2021
+ jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
2022
+ var parent = this.getMatchersClass_();
2023
+ var newMatchersClass = function() {
2024
+ parent.apply(this, arguments);
2025
+ };
2026
+ jasmine.util.inherit(newMatchersClass, parent);
2027
+ jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
2028
+ this.matchersClass = newMatchersClass;
2029
+ };
2030
+
2031
+ jasmine.Spec.prototype.finishCallback = function() {
2032
+ this.env.reporter.reportSpecResults(this);
2033
+ };
2034
+
2035
+ jasmine.Spec.prototype.finish = function(onComplete) {
2036
+ this.removeAllSpies();
2037
+ this.finishCallback();
2038
+ if (onComplete) {
2039
+ onComplete();
2040
+ }
2041
+ };
2042
+
2043
+ jasmine.Spec.prototype.after = function(doAfter) {
2044
+ if (this.queue.isRunning()) {
2045
+ this.queue.add(new jasmine.Block(this.env, doAfter, this));
2046
+ } else {
2047
+ this.afterCallbacks.unshift(doAfter);
2048
+ }
2049
+ };
2050
+
2051
+ jasmine.Spec.prototype.execute = function(onComplete) {
2052
+ var spec = this;
2053
+ if (!spec.env.specFilter(spec)) {
2054
+ spec.results_.skipped = true;
2055
+ spec.finish(onComplete);
2056
+ return;
2057
+ }
2058
+
2059
+ this.env.reporter.reportSpecStarting(this);
2060
+
2061
+ spec.env.currentSpec = spec;
2062
+
2063
+ spec.addBeforesAndAftersToQueue();
2064
+
2065
+ spec.queue.start(function () {
2066
+ spec.finish(onComplete);
2067
+ });
2068
+ };
2069
+
2070
+ jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
2071
+ var runner = this.env.currentRunner();
2072
+ var i;
2073
+
2074
+ for (var suite = this.suite; suite; suite = suite.parentSuite) {
2075
+ for (i = 0; i < suite.before_.length; i++) {
2076
+ this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
2077
+ }
2078
+ }
2079
+ for (i = 0; i < runner.before_.length; i++) {
2080
+ this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
2081
+ }
2082
+ for (i = 0; i < this.afterCallbacks.length; i++) {
2083
+ this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
2084
+ }
2085
+ for (suite = this.suite; suite; suite = suite.parentSuite) {
2086
+ for (i = 0; i < suite.after_.length; i++) {
2087
+ this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
2088
+ }
2089
+ }
2090
+ for (i = 0; i < runner.after_.length; i++) {
2091
+ this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
2092
+ }
2093
+ };
2094
+
2095
+ jasmine.Spec.prototype.explodes = function() {
2096
+ throw 'explodes function should not have been called';
2097
+ };
2098
+
2099
+ jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
2100
+ if (obj == jasmine.undefined) {
2101
+ throw "spyOn could not find an object to spy upon for " + methodName + "()";
2102
+ }
2103
+
2104
+ if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
2105
+ throw methodName + '() method does not exist';
2106
+ }
2107
+
2108
+ if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
2109
+ throw new Error(methodName + ' has already been spied upon');
2110
+ }
2111
+
2112
+ var spyObj = jasmine.createSpy(methodName);
2113
+
2114
+ this.spies_.push(spyObj);
2115
+ spyObj.baseObj = obj;
2116
+ spyObj.methodName = methodName;
2117
+ spyObj.originalValue = obj[methodName];
2118
+
2119
+ obj[methodName] = spyObj;
2120
+
2121
+ return spyObj;
2122
+ };
2123
+
2124
+ jasmine.Spec.prototype.removeAllSpies = function() {
2125
+ for (var i = 0; i < this.spies_.length; i++) {
2126
+ var spy = this.spies_[i];
2127
+ spy.baseObj[spy.methodName] = spy.originalValue;
2128
+ }
2129
+ this.spies_ = [];
2130
+ };
2131
+
2132
+ /**
2133
+ * Internal representation of a Jasmine suite.
2134
+ *
2135
+ * @constructor
2136
+ * @param {jasmine.Env} env
2137
+ * @param {String} description
2138
+ * @param {Function} specDefinitions
2139
+ * @param {jasmine.Suite} parentSuite
2140
+ */
2141
+ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
2142
+ var self = this;
2143
+ self.id = env.nextSuiteId ? env.nextSuiteId() : null;
2144
+ self.description = description;
2145
+ self.queue = new jasmine.Queue(env);
2146
+ self.parentSuite = parentSuite;
2147
+ self.env = env;
2148
+ self.before_ = [];
2149
+ self.after_ = [];
2150
+ self.children_ = [];
2151
+ self.suites_ = [];
2152
+ self.specs_ = [];
2153
+ };
2154
+
2155
+ jasmine.Suite.prototype.getFullName = function() {
2156
+ var fullName = this.description;
2157
+ for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
2158
+ fullName = parentSuite.description + ' ' + fullName;
2159
+ }
2160
+ return fullName;
2161
+ };
2162
+
2163
+ jasmine.Suite.prototype.finish = function(onComplete) {
2164
+ this.env.reporter.reportSuiteResults(this);
2165
+ this.finished = true;
2166
+ if (typeof(onComplete) == 'function') {
2167
+ onComplete();
2168
+ }
2169
+ };
2170
+
2171
+ jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
2172
+ beforeEachFunction.typeName = 'beforeEach';
2173
+ this.before_.unshift(beforeEachFunction);
2174
+ };
2175
+
2176
+ jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
2177
+ afterEachFunction.typeName = 'afterEach';
2178
+ this.after_.unshift(afterEachFunction);
2179
+ };
2180
+
2181
+ jasmine.Suite.prototype.results = function() {
2182
+ return this.queue.results();
2183
+ };
2184
+
2185
+ jasmine.Suite.prototype.add = function(suiteOrSpec) {
2186
+ this.children_.push(suiteOrSpec);
2187
+ if (suiteOrSpec instanceof jasmine.Suite) {
2188
+ this.suites_.push(suiteOrSpec);
2189
+ this.env.currentRunner().addSuite(suiteOrSpec);
2190
+ } else {
2191
+ this.specs_.push(suiteOrSpec);
2192
+ }
2193
+ this.queue.add(suiteOrSpec);
2194
+ };
2195
+
2196
+ jasmine.Suite.prototype.specs = function() {
2197
+ return this.specs_;
2198
+ };
2199
+
2200
+ jasmine.Suite.prototype.suites = function() {
2201
+ return this.suites_;
2202
+ };
2203
+
2204
+ jasmine.Suite.prototype.children = function() {
2205
+ return this.children_;
2206
+ };
2207
+
2208
+ jasmine.Suite.prototype.execute = function(onComplete) {
2209
+ var self = this;
2210
+ this.queue.start(function () {
2211
+ self.finish(onComplete);
2212
+ });
2213
+ };
2214
+ jasmine.WaitsBlock = function(env, timeout, spec) {
2215
+ this.timeout = timeout;
2216
+ jasmine.Block.call(this, env, null, spec);
2217
+ };
2218
+
2219
+ jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
2220
+
2221
+ jasmine.WaitsBlock.prototype.execute = function (onComplete) {
2222
+ if (jasmine.VERBOSE) {
2223
+ this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
2224
+ }
2225
+ this.env.setTimeout(function () {
2226
+ onComplete();
2227
+ }, this.timeout);
2228
+ };
2229
+ /**
2230
+ * A block which waits for some condition to become true, with timeout.
2231
+ *
2232
+ * @constructor
2233
+ * @extends jasmine.Block
2234
+ * @param {jasmine.Env} env The Jasmine environment.
2235
+ * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
2236
+ * @param {Function} latchFunction A function which returns true when the desired condition has been met.
2237
+ * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
2238
+ * @param {jasmine.Spec} spec The Jasmine spec.
2239
+ */
2240
+ jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
2241
+ this.timeout = timeout || env.defaultTimeoutInterval;
2242
+ this.latchFunction = latchFunction;
2243
+ this.message = message;
2244
+ this.totalTimeSpentWaitingForLatch = 0;
2245
+ jasmine.Block.call(this, env, null, spec);
2246
+ };
2247
+ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
2248
+
2249
+ jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
2250
+
2251
+ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
2252
+ if (jasmine.VERBOSE) {
2253
+ this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
2254
+ }
2255
+ var latchFunctionResult;
2256
+ try {
2257
+ latchFunctionResult = this.latchFunction.apply(this.spec);
2258
+ } catch (e) {
2259
+ this.spec.fail(e);
2260
+ onComplete();
2261
+ return;
2262
+ }
2263
+
2264
+ if (latchFunctionResult) {
2265
+ onComplete();
2266
+ } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
2267
+ var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
2268
+ this.spec.fail({
2269
+ name: 'timeout',
2270
+ message: message
2271
+ });
2272
+
2273
+ this.abort = true;
2274
+ onComplete();
2275
+ } else {
2276
+ this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
2277
+ var self = this;
2278
+ this.env.setTimeout(function() {
2279
+ self.execute(onComplete);
2280
+ }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
2281
+ }
2282
+ };
2283
+ // Mock setTimeout, clearTimeout
2284
+ // Contributed by Pivotal Computer Systems, www.pivotalsf.com
2285
+
2286
+ jasmine.FakeTimer = function() {
2287
+ this.reset();
2288
+
2289
+ var self = this;
2290
+ self.setTimeout = function(funcToCall, millis) {
2291
+ self.timeoutsMade++;
2292
+ self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
2293
+ return self.timeoutsMade;
2294
+ };
2295
+
2296
+ self.setInterval = function(funcToCall, millis) {
2297
+ self.timeoutsMade++;
2298
+ self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
2299
+ return self.timeoutsMade;
2300
+ };
2301
+
2302
+ self.clearTimeout = function(timeoutKey) {
2303
+ self.scheduledFunctions[timeoutKey] = jasmine.undefined;
2304
+ };
2305
+
2306
+ self.clearInterval = function(timeoutKey) {
2307
+ self.scheduledFunctions[timeoutKey] = jasmine.undefined;
2308
+ };
2309
+
2310
+ };
2311
+
2312
+ jasmine.FakeTimer.prototype.reset = function() {
2313
+ this.timeoutsMade = 0;
2314
+ this.scheduledFunctions = {};
2315
+ this.nowMillis = 0;
2316
+ };
2317
+
2318
+ jasmine.FakeTimer.prototype.tick = function(millis) {
2319
+ var oldMillis = this.nowMillis;
2320
+ var newMillis = oldMillis + millis;
2321
+ this.runFunctionsWithinRange(oldMillis, newMillis);
2322
+ this.nowMillis = newMillis;
2323
+ };
2324
+
2325
+ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
2326
+ var scheduledFunc;
2327
+ var funcsToRun = [];
2328
+ for (var timeoutKey in this.scheduledFunctions) {
2329
+ scheduledFunc = this.scheduledFunctions[timeoutKey];
2330
+ if (scheduledFunc != jasmine.undefined &&
2331
+ scheduledFunc.runAtMillis >= oldMillis &&
2332
+ scheduledFunc.runAtMillis <= nowMillis) {
2333
+ funcsToRun.push(scheduledFunc);
2334
+ this.scheduledFunctions[timeoutKey] = jasmine.undefined;
2335
+ }
2336
+ }
2337
+
2338
+ if (funcsToRun.length > 0) {
2339
+ funcsToRun.sort(function(a, b) {
2340
+ return a.runAtMillis - b.runAtMillis;
2341
+ });
2342
+ for (var i = 0; i < funcsToRun.length; ++i) {
2343
+ try {
2344
+ var funcToRun = funcsToRun[i];
2345
+ this.nowMillis = funcToRun.runAtMillis;
2346
+ funcToRun.funcToCall();
2347
+ if (funcToRun.recurring) {
2348
+ this.scheduleFunction(funcToRun.timeoutKey,
2349
+ funcToRun.funcToCall,
2350
+ funcToRun.millis,
2351
+ true);
2352
+ }
2353
+ } catch(e) {
2354
+ }
2355
+ }
2356
+ this.runFunctionsWithinRange(oldMillis, nowMillis);
2357
+ }
2358
+ };
2359
+
2360
+ jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
2361
+ this.scheduledFunctions[timeoutKey] = {
2362
+ runAtMillis: this.nowMillis + millis,
2363
+ funcToCall: funcToCall,
2364
+ recurring: recurring,
2365
+ timeoutKey: timeoutKey,
2366
+ millis: millis
2367
+ };
2368
+ };
2369
+
2370
+ /**
2371
+ * @namespace
2372
+ */
2373
+ jasmine.Clock = {
2374
+ defaultFakeTimer: new jasmine.FakeTimer(),
2375
+
2376
+ reset: function() {
2377
+ jasmine.Clock.assertInstalled();
2378
+ jasmine.Clock.defaultFakeTimer.reset();
2379
+ },
2380
+
2381
+ tick: function(millis) {
2382
+ jasmine.Clock.assertInstalled();
2383
+ jasmine.Clock.defaultFakeTimer.tick(millis);
2384
+ },
2385
+
2386
+ runFunctionsWithinRange: function(oldMillis, nowMillis) {
2387
+ jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
2388
+ },
2389
+
2390
+ scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
2391
+ jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
2392
+ },
2393
+
2394
+ useMock: function() {
2395
+ if (!jasmine.Clock.isInstalled()) {
2396
+ var spec = jasmine.getEnv().currentSpec;
2397
+ spec.after(jasmine.Clock.uninstallMock);
2398
+
2399
+ jasmine.Clock.installMock();
2400
+ }
2401
+ },
2402
+
2403
+ installMock: function() {
2404
+ jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
2405
+ },
2406
+
2407
+ uninstallMock: function() {
2408
+ jasmine.Clock.assertInstalled();
2409
+ jasmine.Clock.installed = jasmine.Clock.real;
2410
+ },
2411
+
2412
+ real: {
2413
+ setTimeout: jasmine.getGlobal().setTimeout,
2414
+ clearTimeout: jasmine.getGlobal().clearTimeout,
2415
+ setInterval: jasmine.getGlobal().setInterval,
2416
+ clearInterval: jasmine.getGlobal().clearInterval
2417
+ },
2418
+
2419
+ assertInstalled: function() {
2420
+ if (!jasmine.Clock.isInstalled()) {
2421
+ throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
2422
+ }
2423
+ },
2424
+
2425
+ isInstalled: function() {
2426
+ return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
2427
+ },
2428
+
2429
+ installed: null
2430
+ };
2431
+ jasmine.Clock.installed = jasmine.Clock.real;
2432
+
2433
+ //else for IE support
2434
+ jasmine.getGlobal().setTimeout = function(funcToCall, millis) {
2435
+ if (jasmine.Clock.installed.setTimeout.apply) {
2436
+ return jasmine.Clock.installed.setTimeout.apply(this, arguments);
2437
+ } else {
2438
+ return jasmine.Clock.installed.setTimeout(funcToCall, millis);
2439
+ }
2440
+ };
2441
+
2442
+ jasmine.getGlobal().setInterval = function(funcToCall, millis) {
2443
+ if (jasmine.Clock.installed.setInterval.apply) {
2444
+ return jasmine.Clock.installed.setInterval.apply(this, arguments);
2445
+ } else {
2446
+ return jasmine.Clock.installed.setInterval(funcToCall, millis);
2447
+ }
2448
+ };
2449
+
2450
+ jasmine.getGlobal().clearTimeout = function(timeoutKey) {
2451
+ if (jasmine.Clock.installed.clearTimeout.apply) {
2452
+ return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
2453
+ } else {
2454
+ return jasmine.Clock.installed.clearTimeout(timeoutKey);
2455
+ }
2456
+ };
2457
+
2458
+ jasmine.getGlobal().clearInterval = function(timeoutKey) {
2459
+ if (jasmine.Clock.installed.clearTimeout.apply) {
2460
+ return jasmine.Clock.installed.clearInterval.apply(this, arguments);
2461
+ } else {
2462
+ return jasmine.Clock.installed.clearInterval(timeoutKey);
2463
+ }
2464
+ };
2465
+
2466
+ jasmine.version_= {
2467
+ "major": 1,
2468
+ "minor": 1,
2469
+ "build": 0,
2470
+ "revision": 1308150691
2471
+ }