loris 0.1.4 → 0.1.5

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