teaspoon-jasmine 2.3.4 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5ed50c89e102c349f1f6b002a39b78d236e3ae6d
4
- data.tar.gz: f50a71997b89c28e22f449f79135d260ebd2c8f7
2
+ SHA256:
3
+ metadata.gz: 7f990953e24c5f2a47303aec91cb6a993e5502835413764fe242245ab2759ce9
4
+ data.tar.gz: d612defa21e9c4435ad1d0c5b2bac4713bece1c78ddcb14538ab8163657dc5c3
5
5
  SHA512:
6
- metadata.gz: b15a2a70060eba5b4222ed462cacc8bfdcf97dd0a9d0b7c34196228f163ad5603939804d40f9ad512190f13966b6e8a7475ae070c530c0fd67d268f57785fcf6
7
- data.tar.gz: 027b09f853e81657e972eb47f840f8ab2c16dd6237ae6d19824ba3611b29a48f9cd164c9008af106945b4c15679107421728763dd515bf8b8eb9b3e68c166757
6
+ metadata.gz: 3b3890e71b500040ceac193b1ade8026f391f9ee196b4b1bb8fa0a10a28323378881f8ca871c000a191a97e619cdd1f5a40198b718dfbc7944f6c81be523edcb
7
+ data.tar.gz: 94c56471bef26413794c412bef37700ba47a0100fa5121705990dafcea4c443fe287915dcbd152fac08c6fa598a9b42c9cb0391e0167520ffcc152edb7f98511
@@ -0,0 +1,3454 @@
1
+ /*
2
+ Copyright (c) 2008-2015 Pivotal Labs
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ var getJasmineRequireObj = (function (jasmineGlobal) {
24
+ var jasmineRequire;
25
+
26
+ if (typeof module !== 'undefined' && module.exports) {
27
+ if (typeof global !== 'undefined') {
28
+ jasmineGlobal = global;
29
+ } else {
30
+ jasmineGlobal = {};
31
+ }
32
+ jasmineRequire = exports;
33
+ } else {
34
+ if (typeof window !== 'undefined' && typeof window.toString === 'function' && window.toString() === '[object GjsGlobal]') {
35
+ jasmineGlobal = window;
36
+ }
37
+ jasmineRequire = jasmineGlobal.jasmineRequire = jasmineGlobal.jasmineRequire || {};
38
+ }
39
+
40
+ function getJasmineRequire() {
41
+ return jasmineRequire;
42
+ }
43
+
44
+ getJasmineRequire().core = function(jRequire) {
45
+ var j$ = {};
46
+
47
+ jRequire.base(j$, jasmineGlobal);
48
+ j$.util = jRequire.util();
49
+ j$.errors = jRequire.errors();
50
+ j$.Any = jRequire.Any(j$);
51
+ j$.Anything = jRequire.Anything(j$);
52
+ j$.CallTracker = jRequire.CallTracker();
53
+ j$.MockDate = jRequire.MockDate();
54
+ j$.Clock = jRequire.Clock();
55
+ j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler();
56
+ j$.Env = jRequire.Env(j$);
57
+ j$.ExceptionFormatter = jRequire.ExceptionFormatter();
58
+ j$.Expectation = jRequire.Expectation();
59
+ j$.buildExpectationResult = jRequire.buildExpectationResult();
60
+ j$.JsApiReporter = jRequire.JsApiReporter();
61
+ j$.matchersUtil = jRequire.matchersUtil(j$);
62
+ j$.ObjectContaining = jRequire.ObjectContaining(j$);
63
+ j$.ArrayContaining = jRequire.ArrayContaining(j$);
64
+ j$.pp = jRequire.pp(j$);
65
+ j$.QueueRunner = jRequire.QueueRunner(j$);
66
+ j$.ReportDispatcher = jRequire.ReportDispatcher();
67
+ j$.Spec = jRequire.Spec(j$);
68
+ j$.SpyRegistry = jRequire.SpyRegistry(j$);
69
+ j$.SpyStrategy = jRequire.SpyStrategy();
70
+ j$.StringMatching = jRequire.StringMatching(j$);
71
+ j$.Suite = jRequire.Suite(j$);
72
+ j$.Timer = jRequire.Timer();
73
+ j$.TreeProcessor = jRequire.TreeProcessor();
74
+ j$.version = jRequire.version();
75
+ j$.Order = jRequire.Order();
76
+
77
+ j$.matchers = jRequire.requireMatchers(jRequire, j$);
78
+
79
+ return j$;
80
+ };
81
+
82
+ return getJasmineRequire;
83
+ })(this);
84
+
85
+ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
86
+ var availableMatchers = [
87
+ 'toBe',
88
+ 'toBeCloseTo',
89
+ 'toBeDefined',
90
+ 'toBeFalsy',
91
+ 'toBeGreaterThan',
92
+ 'toBeLessThan',
93
+ 'toBeNaN',
94
+ 'toBeNull',
95
+ 'toBeTruthy',
96
+ 'toBeUndefined',
97
+ 'toContain',
98
+ 'toEqual',
99
+ 'toHaveBeenCalled',
100
+ 'toHaveBeenCalledWith',
101
+ 'toHaveBeenCalledTimes',
102
+ 'toMatch',
103
+ 'toThrow',
104
+ 'toThrowError'
105
+ ],
106
+ matchers = {};
107
+
108
+ for (var i = 0; i < availableMatchers.length; i++) {
109
+ var name = availableMatchers[i];
110
+ matchers[name] = jRequire[name](j$);
111
+ }
112
+
113
+ return matchers;
114
+ };
115
+
116
+ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
117
+ j$.unimplementedMethod_ = function() {
118
+ throw new Error('unimplemented method');
119
+ };
120
+
121
+ j$.MAX_PRETTY_PRINT_DEPTH = 40;
122
+ j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100;
123
+ j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
124
+
125
+ j$.getGlobal = function() {
126
+ return jasmineGlobal;
127
+ };
128
+
129
+ j$.getEnv = function(options) {
130
+ var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);
131
+ //jasmine. singletons in here (setTimeout blah blah).
132
+ return env;
133
+ };
134
+
135
+ j$.isArray_ = function(value) {
136
+ return j$.isA_('Array', value);
137
+ };
138
+
139
+ j$.isString_ = function(value) {
140
+ return j$.isA_('String', value);
141
+ };
142
+
143
+ j$.isNumber_ = function(value) {
144
+ return j$.isA_('Number', value);
145
+ };
146
+
147
+ j$.isA_ = function(typeName, value) {
148
+ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
149
+ };
150
+
151
+ j$.isDomNode = function(obj) {
152
+ return obj.nodeType > 0;
153
+ };
154
+
155
+ j$.fnNameFor = function(func) {
156
+ return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
157
+ };
158
+
159
+ j$.any = function(clazz) {
160
+ return new j$.Any(clazz);
161
+ };
162
+
163
+ j$.anything = function() {
164
+ return new j$.Anything();
165
+ };
166
+
167
+ j$.objectContaining = function(sample) {
168
+ return new j$.ObjectContaining(sample);
169
+ };
170
+
171
+ j$.stringMatching = function(expected) {
172
+ return new j$.StringMatching(expected);
173
+ };
174
+
175
+ j$.arrayContaining = function(sample) {
176
+ return new j$.ArrayContaining(sample);
177
+ };
178
+
179
+ j$.createSpy = function(name, originalFn) {
180
+
181
+ var spyStrategy = new j$.SpyStrategy({
182
+ name: name,
183
+ fn: originalFn,
184
+ getSpy: function() { return spy; }
185
+ }),
186
+ callTracker = new j$.CallTracker(),
187
+ spy = function() {
188
+ var callData = {
189
+ object: this,
190
+ args: Array.prototype.slice.apply(arguments)
191
+ };
192
+
193
+ callTracker.track(callData);
194
+ var returnValue = spyStrategy.exec.apply(this, arguments);
195
+ callData.returnValue = returnValue;
196
+
197
+ return returnValue;
198
+ };
199
+
200
+ for (var prop in originalFn) {
201
+ if (prop === 'and' || prop === 'calls') {
202
+ throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon');
203
+ }
204
+
205
+ spy[prop] = originalFn[prop];
206
+ }
207
+
208
+ spy.and = spyStrategy;
209
+ spy.calls = callTracker;
210
+
211
+ return spy;
212
+ };
213
+
214
+ j$.isSpy = function(putativeSpy) {
215
+ if (!putativeSpy) {
216
+ return false;
217
+ }
218
+ return putativeSpy.and instanceof j$.SpyStrategy &&
219
+ putativeSpy.calls instanceof j$.CallTracker;
220
+ };
221
+
222
+ j$.createSpyObj = function(baseName, methodNames) {
223
+ if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) {
224
+ methodNames = baseName;
225
+ baseName = 'unknown';
226
+ }
227
+
228
+ if (!j$.isArray_(methodNames) || methodNames.length === 0) {
229
+ throw 'createSpyObj requires a non-empty array of method names to create spies for';
230
+ }
231
+ var obj = {};
232
+ for (var i = 0; i < methodNames.length; i++) {
233
+ obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
234
+ }
235
+ return obj;
236
+ };
237
+ };
238
+
239
+ getJasmineRequireObj().util = function() {
240
+
241
+ var util = {};
242
+
243
+ util.inherit = function(childClass, parentClass) {
244
+ var Subclass = function() {
245
+ };
246
+ Subclass.prototype = parentClass.prototype;
247
+ childClass.prototype = new Subclass();
248
+ };
249
+
250
+ util.htmlEscape = function(str) {
251
+ if (!str) {
252
+ return str;
253
+ }
254
+ return str.replace(/&/g, '&amp;')
255
+ .replace(/</g, '&lt;')
256
+ .replace(/>/g, '&gt;');
257
+ };
258
+
259
+ util.argsToArray = function(args) {
260
+ var arrayOfArgs = [];
261
+ for (var i = 0; i < args.length; i++) {
262
+ arrayOfArgs.push(args[i]);
263
+ }
264
+ return arrayOfArgs;
265
+ };
266
+
267
+ util.isUndefined = function(obj) {
268
+ return obj === void 0;
269
+ };
270
+
271
+ util.arrayContains = function(array, search) {
272
+ var i = array.length;
273
+ while (i--) {
274
+ if (array[i] === search) {
275
+ return true;
276
+ }
277
+ }
278
+ return false;
279
+ };
280
+
281
+ util.clone = function(obj) {
282
+ if (Object.prototype.toString.apply(obj) === '[object Array]') {
283
+ return obj.slice();
284
+ }
285
+
286
+ var cloned = {};
287
+ for (var prop in obj) {
288
+ if (obj.hasOwnProperty(prop)) {
289
+ cloned[prop] = obj[prop];
290
+ }
291
+ }
292
+
293
+ return cloned;
294
+ };
295
+
296
+ return util;
297
+ };
298
+
299
+ getJasmineRequireObj().Spec = function(j$) {
300
+ function Spec(attrs) {
301
+ this.expectationFactory = attrs.expectationFactory;
302
+ this.resultCallback = attrs.resultCallback || function() {};
303
+ this.id = attrs.id;
304
+ this.description = attrs.description || '';
305
+ this.queueableFn = attrs.queueableFn;
306
+ this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; };
307
+ this.userContext = attrs.userContext || function() { return {}; };
308
+ this.onStart = attrs.onStart || function() {};
309
+ this.getSpecName = attrs.getSpecName || function() { return ''; };
310
+ this.expectationResultFactory = attrs.expectationResultFactory || function() { };
311
+ this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
312
+ this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
313
+ this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
314
+
315
+ if (!this.queueableFn.fn) {
316
+ this.pend();
317
+ }
318
+
319
+ this.result = {
320
+ id: this.id,
321
+ description: this.description,
322
+ fullName: this.getFullName(),
323
+ failedExpectations: [],
324
+ passedExpectations: [],
325
+ pendingReason: ''
326
+ };
327
+ }
328
+
329
+ Spec.prototype.addExpectationResult = function(passed, data, isError) {
330
+ var expectationResult = this.expectationResultFactory(data);
331
+ if (passed) {
332
+ this.result.passedExpectations.push(expectationResult);
333
+ } else {
334
+ this.result.failedExpectations.push(expectationResult);
335
+
336
+ if (this.throwOnExpectationFailure && !isError) {
337
+ throw new j$.errors.ExpectationFailed();
338
+ }
339
+ }
340
+ };
341
+
342
+ Spec.prototype.expect = function(actual) {
343
+ return this.expectationFactory(actual, this);
344
+ };
345
+
346
+ Spec.prototype.execute = function(onComplete, enabled) {
347
+ var self = this;
348
+
349
+ this.onStart(this);
350
+
351
+ if (!this.isExecutable() || this.markedPending || enabled === false) {
352
+ complete(enabled);
353
+ return;
354
+ }
355
+
356
+ var fns = this.beforeAndAfterFns();
357
+ var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
358
+
359
+ this.queueRunnerFactory({
360
+ queueableFns: allFns,
361
+ onException: function() { self.onException.apply(self, arguments); },
362
+ onComplete: complete,
363
+ userContext: this.userContext()
364
+ });
365
+
366
+ function complete(enabledAgain) {
367
+ self.result.status = self.status(enabledAgain);
368
+ self.resultCallback(self.result);
369
+
370
+ if (onComplete) {
371
+ onComplete();
372
+ }
373
+ }
374
+ };
375
+
376
+ Spec.prototype.onException = function onException(e) {
377
+ if (Spec.isPendingSpecException(e)) {
378
+ this.pend(extractCustomPendingMessage(e));
379
+ return;
380
+ }
381
+
382
+ if (e instanceof j$.errors.ExpectationFailed) {
383
+ return;
384
+ }
385
+
386
+ this.addExpectationResult(false, {
387
+ matcherName: '',
388
+ passed: false,
389
+ expected: '',
390
+ actual: '',
391
+ error: e
392
+ }, true);
393
+ };
394
+
395
+ Spec.prototype.disable = function() {
396
+ this.disabled = true;
397
+ };
398
+
399
+ Spec.prototype.pend = function(message) {
400
+ this.markedPending = true;
401
+ if (message) {
402
+ this.result.pendingReason = message;
403
+ }
404
+ };
405
+
406
+ Spec.prototype.getResult = function() {
407
+ this.result.status = this.status();
408
+ return this.result;
409
+ };
410
+
411
+ Spec.prototype.status = function(enabled) {
412
+ if (this.disabled || enabled === false) {
413
+ return 'disabled';
414
+ }
415
+
416
+ if (this.markedPending) {
417
+ return 'pending';
418
+ }
419
+
420
+ if (this.result.failedExpectations.length > 0) {
421
+ return 'failed';
422
+ } else {
423
+ return 'passed';
424
+ }
425
+ };
426
+
427
+ Spec.prototype.isExecutable = function() {
428
+ return !this.disabled;
429
+ };
430
+
431
+ Spec.prototype.getFullName = function() {
432
+ return this.getSpecName(this);
433
+ };
434
+
435
+ var extractCustomPendingMessage = function(e) {
436
+ var fullMessage = e.toString(),
437
+ boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
438
+ boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length;
439
+
440
+ return fullMessage.substr(boilerplateEnd);
441
+ };
442
+
443
+ Spec.pendingSpecExceptionMessage = '=> marked Pending';
444
+
445
+ Spec.isPendingSpecException = function(e) {
446
+ return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1);
447
+ };
448
+
449
+ return Spec;
450
+ };
451
+
452
+ if (typeof window == void 0 && typeof exports == 'object') {
453
+ exports.Spec = jasmineRequire.Spec;
454
+ }
455
+
456
+ /*jshint bitwise: false*/
457
+
458
+ getJasmineRequireObj().Order = function() {
459
+ function Order(options) {
460
+ this.random = 'random' in options ? options.random : true;
461
+ var seed = this.seed = options.seed || generateSeed();
462
+ this.sort = this.random ? randomOrder : naturalOrder;
463
+
464
+ function naturalOrder(items) {
465
+ return items;
466
+ }
467
+
468
+ function randomOrder(items) {
469
+ var copy = items.slice();
470
+ copy.sort(function(a, b) {
471
+ return jenkinsHash(seed + a.id) - jenkinsHash(seed + b.id);
472
+ });
473
+ return copy;
474
+ }
475
+
476
+ function generateSeed() {
477
+ return String(Math.random()).slice(-5);
478
+ }
479
+
480
+ // Bob Jenkins One-at-a-Time Hash algorithm is a non-cryptographic hash function
481
+ // used to get a different output when the key changes slighly.
482
+ // We use your return to sort the children randomly in a consistent way when
483
+ // used in conjunction with a seed
484
+
485
+ function jenkinsHash(key) {
486
+ var hash, i;
487
+ for(hash = i = 0; i < key.length; ++i) {
488
+ hash += key.charCodeAt(i);
489
+ hash += (hash << 10);
490
+ hash ^= (hash >> 6);
491
+ }
492
+ hash += (hash << 3);
493
+ hash ^= (hash >> 11);
494
+ hash += (hash << 15);
495
+ return hash;
496
+ }
497
+
498
+ }
499
+
500
+ return Order;
501
+ };
502
+
503
+ getJasmineRequireObj().Env = function(j$) {
504
+ function Env(options) {
505
+ options = options || {};
506
+
507
+ var self = this;
508
+ var global = options.global || j$.getGlobal();
509
+
510
+ var totalSpecsDefined = 0;
511
+
512
+ var catchExceptions = true;
513
+
514
+ var realSetTimeout = j$.getGlobal().setTimeout;
515
+ var realClearTimeout = j$.getGlobal().clearTimeout;
516
+ this.clock = new j$.Clock(global, function () { return new j$.DelayedFunctionScheduler(); }, new j$.MockDate(global));
517
+
518
+ var runnableLookupTable = {};
519
+ var runnableResources = {};
520
+
521
+ var currentSpec = null;
522
+ var currentlyExecutingSuites = [];
523
+ var currentDeclarationSuite = null;
524
+ var throwOnExpectationFailure = false;
525
+ var random = false;
526
+ var seed = null;
527
+
528
+ var currentSuite = function() {
529
+ return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
530
+ };
531
+
532
+ var currentRunnable = function() {
533
+ return currentSpec || currentSuite();
534
+ };
535
+
536
+ var reporter = new j$.ReportDispatcher([
537
+ 'jasmineStarted',
538
+ 'jasmineDone',
539
+ 'suiteStarted',
540
+ 'suiteDone',
541
+ 'specStarted',
542
+ 'specDone'
543
+ ]);
544
+
545
+ this.specFilter = function() {
546
+ return true;
547
+ };
548
+
549
+ this.addCustomEqualityTester = function(tester) {
550
+ if(!currentRunnable()) {
551
+ throw new Error('Custom Equalities must be added in a before function or a spec');
552
+ }
553
+ runnableResources[currentRunnable().id].customEqualityTesters.push(tester);
554
+ };
555
+
556
+ this.addMatchers = function(matchersToAdd) {
557
+ if(!currentRunnable()) {
558
+ throw new Error('Matchers must be added in a before function or a spec');
559
+ }
560
+ var customMatchers = runnableResources[currentRunnable().id].customMatchers;
561
+ for (var matcherName in matchersToAdd) {
562
+ customMatchers[matcherName] = matchersToAdd[matcherName];
563
+ }
564
+ };
565
+
566
+ j$.Expectation.addCoreMatchers(j$.matchers);
567
+
568
+ var nextSpecId = 0;
569
+ var getNextSpecId = function() {
570
+ return 'spec' + nextSpecId++;
571
+ };
572
+
573
+ var nextSuiteId = 0;
574
+ var getNextSuiteId = function() {
575
+ return 'suite' + nextSuiteId++;
576
+ };
577
+
578
+ var expectationFactory = function(actual, spec) {
579
+ return j$.Expectation.Factory({
580
+ util: j$.matchersUtil,
581
+ customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
582
+ customMatchers: runnableResources[spec.id].customMatchers,
583
+ actual: actual,
584
+ addExpectationResult: addExpectationResult
585
+ });
586
+
587
+ function addExpectationResult(passed, result) {
588
+ return spec.addExpectationResult(passed, result);
589
+ }
590
+ };
591
+
592
+ var defaultResourcesForRunnable = function(id, parentRunnableId) {
593
+ var resources = {spies: [], customEqualityTesters: [], customMatchers: {}};
594
+
595
+ if(runnableResources[parentRunnableId]){
596
+ resources.customEqualityTesters = j$.util.clone(runnableResources[parentRunnableId].customEqualityTesters);
597
+ resources.customMatchers = j$.util.clone(runnableResources[parentRunnableId].customMatchers);
598
+ }
599
+
600
+ runnableResources[id] = resources;
601
+ };
602
+
603
+ var clearResourcesForRunnable = function(id) {
604
+ spyRegistry.clearSpies();
605
+ delete runnableResources[id];
606
+ };
607
+
608
+ var beforeAndAfterFns = function(suite) {
609
+ return function() {
610
+ var befores = [],
611
+ afters = [];
612
+
613
+ while(suite) {
614
+ befores = befores.concat(suite.beforeFns);
615
+ afters = afters.concat(suite.afterFns);
616
+
617
+ suite = suite.parentSuite;
618
+ }
619
+
620
+ return {
621
+ befores: befores.reverse(),
622
+ afters: afters
623
+ };
624
+ };
625
+ };
626
+
627
+ var getSpecName = function(spec, suite) {
628
+ return suite.getFullName() + ' ' + spec.description;
629
+ };
630
+
631
+ // TODO: we may just be able to pass in the fn instead of wrapping here
632
+ var buildExpectationResult = j$.buildExpectationResult,
633
+ exceptionFormatter = new j$.ExceptionFormatter(),
634
+ expectationResultFactory = function(attrs) {
635
+ attrs.messageFormatter = exceptionFormatter.message;
636
+ attrs.stackFormatter = exceptionFormatter.stack;
637
+
638
+ return buildExpectationResult(attrs);
639
+ };
640
+
641
+ // TODO: fix this naming, and here's where the value comes in
642
+ this.catchExceptions = function(value) {
643
+ catchExceptions = !!value;
644
+ return catchExceptions;
645
+ };
646
+
647
+ this.catchingExceptions = function() {
648
+ return catchExceptions;
649
+ };
650
+
651
+ var maximumSpecCallbackDepth = 20;
652
+ var currentSpecCallbackDepth = 0;
653
+
654
+ function clearStack(fn) {
655
+ currentSpecCallbackDepth++;
656
+ if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) {
657
+ currentSpecCallbackDepth = 0;
658
+ realSetTimeout(fn, 0);
659
+ } else {
660
+ fn();
661
+ }
662
+ }
663
+
664
+ var catchException = function(e) {
665
+ return j$.Spec.isPendingSpecException(e) || catchExceptions;
666
+ };
667
+
668
+ this.throwOnExpectationFailure = function(value) {
669
+ throwOnExpectationFailure = !!value;
670
+ };
671
+
672
+ this.throwingExpectationFailures = function() {
673
+ return throwOnExpectationFailure;
674
+ };
675
+
676
+ this.randomizeTests = function(value) {
677
+ random = !!value;
678
+ };
679
+
680
+ this.randomTests = function() {
681
+ return random;
682
+ };
683
+
684
+ this.seed = function(value) {
685
+ if (value) {
686
+ seed = value;
687
+ }
688
+ return seed;
689
+ };
690
+
691
+ var queueRunnerFactory = function(options) {
692
+ options.catchException = catchException;
693
+ options.clearStack = options.clearStack || clearStack;
694
+ options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
695
+ options.fail = self.fail;
696
+
697
+ new j$.QueueRunner(options).execute();
698
+ };
699
+
700
+ var topSuite = new j$.Suite({
701
+ env: this,
702
+ id: getNextSuiteId(),
703
+ description: 'Jasmine__TopLevel__Suite',
704
+ queueRunner: queueRunnerFactory
705
+ });
706
+ runnableLookupTable[topSuite.id] = topSuite;
707
+ defaultResourcesForRunnable(topSuite.id);
708
+ currentDeclarationSuite = topSuite;
709
+
710
+ this.topSuite = function() {
711
+ return topSuite;
712
+ };
713
+
714
+ this.execute = function(runnablesToRun) {
715
+ if(!runnablesToRun) {
716
+ if (focusedRunnables.length) {
717
+ runnablesToRun = focusedRunnables;
718
+ } else {
719
+ runnablesToRun = [topSuite.id];
720
+ }
721
+ }
722
+
723
+ var order = new j$.Order({
724
+ random: random,
725
+ seed: seed
726
+ });
727
+
728
+ var processor = new j$.TreeProcessor({
729
+ tree: topSuite,
730
+ runnableIds: runnablesToRun,
731
+ queueRunnerFactory: queueRunnerFactory,
732
+ nodeStart: function(suite) {
733
+ currentlyExecutingSuites.push(suite);
734
+ defaultResourcesForRunnable(suite.id, suite.parentSuite.id);
735
+ reporter.suiteStarted(suite.result);
736
+ },
737
+ nodeComplete: function(suite, result) {
738
+ if (!suite.disabled) {
739
+ clearResourcesForRunnable(suite.id);
740
+ }
741
+ currentlyExecutingSuites.pop();
742
+ reporter.suiteDone(result);
743
+ },
744
+ orderChildren: function(node) {
745
+ return order.sort(node.children);
746
+ }
747
+ });
748
+
749
+ if(!processor.processTree().valid) {
750
+ throw new Error('Invalid order: would cause a beforeAll or afterAll to be run multiple times');
751
+ }
752
+
753
+ reporter.jasmineStarted({
754
+ totalSpecsDefined: totalSpecsDefined
755
+ });
756
+
757
+ processor.execute(function() {
758
+ reporter.jasmineDone({
759
+ order: order
760
+ });
761
+ });
762
+ };
763
+
764
+ this.addReporter = function(reporterToAdd) {
765
+ reporter.addReporter(reporterToAdd);
766
+ };
767
+
768
+ var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
769
+ if(!currentRunnable()) {
770
+ throw new Error('Spies must be created in a before function or a spec');
771
+ }
772
+ return runnableResources[currentRunnable().id].spies;
773
+ }});
774
+
775
+ this.spyOn = function() {
776
+ return spyRegistry.spyOn.apply(spyRegistry, arguments);
777
+ };
778
+
779
+ var suiteFactory = function(description) {
780
+ var suite = new j$.Suite({
781
+ env: self,
782
+ id: getNextSuiteId(),
783
+ description: description,
784
+ parentSuite: currentDeclarationSuite,
785
+ expectationFactory: expectationFactory,
786
+ expectationResultFactory: expectationResultFactory,
787
+ throwOnExpectationFailure: throwOnExpectationFailure
788
+ });
789
+
790
+ runnableLookupTable[suite.id] = suite;
791
+ return suite;
792
+ };
793
+
794
+ this.describe = function(description, specDefinitions) {
795
+ var suite = suiteFactory(description);
796
+ if (specDefinitions.length > 0) {
797
+ throw new Error('describe does not expect a done parameter');
798
+ }
799
+ if (currentDeclarationSuite.markedPending) {
800
+ suite.pend();
801
+ }
802
+ addSpecsToSuite(suite, specDefinitions);
803
+ return suite;
804
+ };
805
+
806
+ this.xdescribe = function(description, specDefinitions) {
807
+ var suite = suiteFactory(description);
808
+ suite.pend();
809
+ addSpecsToSuite(suite, specDefinitions);
810
+ return suite;
811
+ };
812
+
813
+ var focusedRunnables = [];
814
+
815
+ this.fdescribe = function(description, specDefinitions) {
816
+ var suite = suiteFactory(description);
817
+ suite.isFocused = true;
818
+
819
+ focusedRunnables.push(suite.id);
820
+ unfocusAncestor();
821
+ addSpecsToSuite(suite, specDefinitions);
822
+
823
+ return suite;
824
+ };
825
+
826
+ function addSpecsToSuite(suite, specDefinitions) {
827
+ var parentSuite = currentDeclarationSuite;
828
+ parentSuite.addChild(suite);
829
+ currentDeclarationSuite = suite;
830
+
831
+ var declarationError = null;
832
+ try {
833
+ specDefinitions.call(suite);
834
+ } catch (e) {
835
+ declarationError = e;
836
+ }
837
+
838
+ if (declarationError) {
839
+ self.it('encountered a declaration exception', function() {
840
+ throw declarationError;
841
+ });
842
+ }
843
+
844
+ currentDeclarationSuite = parentSuite;
845
+ }
846
+
847
+ function findFocusedAncestor(suite) {
848
+ while (suite) {
849
+ if (suite.isFocused) {
850
+ return suite.id;
851
+ }
852
+ suite = suite.parentSuite;
853
+ }
854
+
855
+ return null;
856
+ }
857
+
858
+ function unfocusAncestor() {
859
+ var focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
860
+ if (focusedAncestor) {
861
+ for (var i = 0; i < focusedRunnables.length; i++) {
862
+ if (focusedRunnables[i] === focusedAncestor) {
863
+ focusedRunnables.splice(i, 1);
864
+ break;
865
+ }
866
+ }
867
+ }
868
+ }
869
+
870
+ var specFactory = function(description, fn, suite, timeout) {
871
+ totalSpecsDefined++;
872
+ var spec = new j$.Spec({
873
+ id: getNextSpecId(),
874
+ beforeAndAfterFns: beforeAndAfterFns(suite),
875
+ expectationFactory: expectationFactory,
876
+ resultCallback: specResultCallback,
877
+ getSpecName: function(spec) {
878
+ return getSpecName(spec, suite);
879
+ },
880
+ onStart: specStarted,
881
+ description: description,
882
+ expectationResultFactory: expectationResultFactory,
883
+ queueRunnerFactory: queueRunnerFactory,
884
+ userContext: function() { return suite.clonedSharedUserContext(); },
885
+ queueableFn: {
886
+ fn: fn,
887
+ timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
888
+ },
889
+ throwOnExpectationFailure: throwOnExpectationFailure
890
+ });
891
+
892
+ runnableLookupTable[spec.id] = spec;
893
+
894
+ if (!self.specFilter(spec)) {
895
+ spec.disable();
896
+ }
897
+
898
+ return spec;
899
+
900
+ function specResultCallback(result) {
901
+ clearResourcesForRunnable(spec.id);
902
+ currentSpec = null;
903
+ reporter.specDone(result);
904
+ }
905
+
906
+ function specStarted(spec) {
907
+ currentSpec = spec;
908
+ defaultResourcesForRunnable(spec.id, suite.id);
909
+ reporter.specStarted(spec.result);
910
+ }
911
+ };
912
+
913
+ this.it = function(description, fn, timeout) {
914
+ var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
915
+ if (currentDeclarationSuite.markedPending) {
916
+ spec.pend();
917
+ }
918
+ currentDeclarationSuite.addChild(spec);
919
+ return spec;
920
+ };
921
+
922
+ this.xit = function() {
923
+ var spec = this.it.apply(this, arguments);
924
+ spec.pend('Temporarily disabled with xit');
925
+ return spec;
926
+ };
927
+
928
+ this.fit = function(description, fn, timeout){
929
+ var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
930
+ currentDeclarationSuite.addChild(spec);
931
+ focusedRunnables.push(spec.id);
932
+ unfocusAncestor();
933
+ return spec;
934
+ };
935
+
936
+ this.expect = function(actual) {
937
+ if (!currentRunnable()) {
938
+ throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out');
939
+ }
940
+
941
+ return currentRunnable().expect(actual);
942
+ };
943
+
944
+ this.beforeEach = function(beforeEachFunction, timeout) {
945
+ currentDeclarationSuite.beforeEach({
946
+ fn: beforeEachFunction,
947
+ timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
948
+ });
949
+ };
950
+
951
+ this.beforeAll = function(beforeAllFunction, timeout) {
952
+ currentDeclarationSuite.beforeAll({
953
+ fn: beforeAllFunction,
954
+ timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
955
+ });
956
+ };
957
+
958
+ this.afterEach = function(afterEachFunction, timeout) {
959
+ currentDeclarationSuite.afterEach({
960
+ fn: afterEachFunction,
961
+ timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
962
+ });
963
+ };
964
+
965
+ this.afterAll = function(afterAllFunction, timeout) {
966
+ currentDeclarationSuite.afterAll({
967
+ fn: afterAllFunction,
968
+ timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
969
+ });
970
+ };
971
+
972
+ this.pending = function(message) {
973
+ var fullMessage = j$.Spec.pendingSpecExceptionMessage;
974
+ if(message) {
975
+ fullMessage += message;
976
+ }
977
+ throw fullMessage;
978
+ };
979
+
980
+ this.fail = function(error) {
981
+ var message = 'Failed';
982
+ if (error) {
983
+ message += ': ';
984
+ message += error.message || error;
985
+ }
986
+
987
+ currentRunnable().addExpectationResult(false, {
988
+ matcherName: '',
989
+ passed: false,
990
+ expected: '',
991
+ actual: '',
992
+ message: message,
993
+ error: error && error.message ? error : null
994
+ });
995
+ };
996
+ }
997
+
998
+ return Env;
999
+ };
1000
+
1001
+ getJasmineRequireObj().JsApiReporter = function() {
1002
+
1003
+ var noopTimer = {
1004
+ start: function(){},
1005
+ elapsed: function(){ return 0; }
1006
+ };
1007
+
1008
+ function JsApiReporter(options) {
1009
+ var timer = options.timer || noopTimer,
1010
+ status = 'loaded';
1011
+
1012
+ this.started = false;
1013
+ this.finished = false;
1014
+ this.runDetails = {};
1015
+
1016
+ this.jasmineStarted = function() {
1017
+ this.started = true;
1018
+ status = 'started';
1019
+ timer.start();
1020
+ };
1021
+
1022
+ var executionTime;
1023
+
1024
+ this.jasmineDone = function(runDetails) {
1025
+ this.finished = true;
1026
+ this.runDetails = runDetails;
1027
+ executionTime = timer.elapsed();
1028
+ status = 'done';
1029
+ };
1030
+
1031
+ this.status = function() {
1032
+ return status;
1033
+ };
1034
+
1035
+ var suites = [],
1036
+ suites_hash = {};
1037
+
1038
+ this.suiteStarted = function(result) {
1039
+ suites_hash[result.id] = result;
1040
+ };
1041
+
1042
+ this.suiteDone = function(result) {
1043
+ storeSuite(result);
1044
+ };
1045
+
1046
+ this.suiteResults = function(index, length) {
1047
+ return suites.slice(index, index + length);
1048
+ };
1049
+
1050
+ function storeSuite(result) {
1051
+ suites.push(result);
1052
+ suites_hash[result.id] = result;
1053
+ }
1054
+
1055
+ this.suites = function() {
1056
+ return suites_hash;
1057
+ };
1058
+
1059
+ var specs = [];
1060
+
1061
+ this.specDone = function(result) {
1062
+ specs.push(result);
1063
+ };
1064
+
1065
+ this.specResults = function(index, length) {
1066
+ return specs.slice(index, index + length);
1067
+ };
1068
+
1069
+ this.specs = function() {
1070
+ return specs;
1071
+ };
1072
+
1073
+ this.executionTime = function() {
1074
+ return executionTime;
1075
+ };
1076
+
1077
+ }
1078
+
1079
+ return JsApiReporter;
1080
+ };
1081
+
1082
+ getJasmineRequireObj().CallTracker = function() {
1083
+
1084
+ function CallTracker() {
1085
+ var calls = [];
1086
+
1087
+ this.track = function(context) {
1088
+ calls.push(context);
1089
+ };
1090
+
1091
+ this.any = function() {
1092
+ return !!calls.length;
1093
+ };
1094
+
1095
+ this.count = function() {
1096
+ return calls.length;
1097
+ };
1098
+
1099
+ this.argsFor = function(index) {
1100
+ var call = calls[index];
1101
+ return call ? call.args : [];
1102
+ };
1103
+
1104
+ this.all = function() {
1105
+ return calls;
1106
+ };
1107
+
1108
+ this.allArgs = function() {
1109
+ var callArgs = [];
1110
+ for(var i = 0; i < calls.length; i++){
1111
+ callArgs.push(calls[i].args);
1112
+ }
1113
+
1114
+ return callArgs;
1115
+ };
1116
+
1117
+ this.first = function() {
1118
+ return calls[0];
1119
+ };
1120
+
1121
+ this.mostRecent = function() {
1122
+ return calls[calls.length - 1];
1123
+ };
1124
+
1125
+ this.reset = function() {
1126
+ calls = [];
1127
+ };
1128
+ }
1129
+
1130
+ return CallTracker;
1131
+ };
1132
+
1133
+ getJasmineRequireObj().Clock = function() {
1134
+ function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
1135
+ var self = this,
1136
+ realTimingFunctions = {
1137
+ setTimeout: global.setTimeout,
1138
+ clearTimeout: global.clearTimeout,
1139
+ setInterval: global.setInterval,
1140
+ clearInterval: global.clearInterval
1141
+ },
1142
+ fakeTimingFunctions = {
1143
+ setTimeout: setTimeout,
1144
+ clearTimeout: clearTimeout,
1145
+ setInterval: setInterval,
1146
+ clearInterval: clearInterval
1147
+ },
1148
+ installed = false,
1149
+ delayedFunctionScheduler,
1150
+ timer;
1151
+
1152
+
1153
+ self.install = function() {
1154
+ if(!originalTimingFunctionsIntact()) {
1155
+ throw new Error('Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?');
1156
+ }
1157
+ replace(global, fakeTimingFunctions);
1158
+ timer = fakeTimingFunctions;
1159
+ delayedFunctionScheduler = delayedFunctionSchedulerFactory();
1160
+ installed = true;
1161
+
1162
+ return self;
1163
+ };
1164
+
1165
+ self.uninstall = function() {
1166
+ delayedFunctionScheduler = null;
1167
+ mockDate.uninstall();
1168
+ replace(global, realTimingFunctions);
1169
+
1170
+ timer = realTimingFunctions;
1171
+ installed = false;
1172
+ };
1173
+
1174
+ self.withMock = function(closure) {
1175
+ this.install();
1176
+ try {
1177
+ closure();
1178
+ } finally {
1179
+ this.uninstall();
1180
+ }
1181
+ };
1182
+
1183
+ self.mockDate = function(initialDate) {
1184
+ mockDate.install(initialDate);
1185
+ };
1186
+
1187
+ self.setTimeout = function(fn, delay, params) {
1188
+ if (legacyIE()) {
1189
+ if (arguments.length > 2) {
1190
+ throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill');
1191
+ }
1192
+ return timer.setTimeout(fn, delay);
1193
+ }
1194
+ return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]);
1195
+ };
1196
+
1197
+ self.setInterval = function(fn, delay, params) {
1198
+ if (legacyIE()) {
1199
+ if (arguments.length > 2) {
1200
+ throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill');
1201
+ }
1202
+ return timer.setInterval(fn, delay);
1203
+ }
1204
+ return Function.prototype.apply.apply(timer.setInterval, [global, arguments]);
1205
+ };
1206
+
1207
+ self.clearTimeout = function(id) {
1208
+ return Function.prototype.call.apply(timer.clearTimeout, [global, id]);
1209
+ };
1210
+
1211
+ self.clearInterval = function(id) {
1212
+ return Function.prototype.call.apply(timer.clearInterval, [global, id]);
1213
+ };
1214
+
1215
+ self.tick = function(millis) {
1216
+ if (installed) {
1217
+ mockDate.tick(millis);
1218
+ delayedFunctionScheduler.tick(millis);
1219
+ } else {
1220
+ throw new Error('Mock clock is not installed, use jasmine.clock().install()');
1221
+ }
1222
+ };
1223
+
1224
+ return self;
1225
+
1226
+ function originalTimingFunctionsIntact() {
1227
+ return global.setTimeout === realTimingFunctions.setTimeout &&
1228
+ global.clearTimeout === realTimingFunctions.clearTimeout &&
1229
+ global.setInterval === realTimingFunctions.setInterval &&
1230
+ global.clearInterval === realTimingFunctions.clearInterval;
1231
+ }
1232
+
1233
+ function legacyIE() {
1234
+ //if these methods are polyfilled, apply will be present
1235
+ return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply;
1236
+ }
1237
+
1238
+ function replace(dest, source) {
1239
+ for (var prop in source) {
1240
+ dest[prop] = source[prop];
1241
+ }
1242
+ }
1243
+
1244
+ function setTimeout(fn, delay) {
1245
+ return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2));
1246
+ }
1247
+
1248
+ function clearTimeout(id) {
1249
+ return delayedFunctionScheduler.removeFunctionWithId(id);
1250
+ }
1251
+
1252
+ function setInterval(fn, interval) {
1253
+ return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true);
1254
+ }
1255
+
1256
+ function clearInterval(id) {
1257
+ return delayedFunctionScheduler.removeFunctionWithId(id);
1258
+ }
1259
+
1260
+ function argSlice(argsObj, n) {
1261
+ return Array.prototype.slice.call(argsObj, n);
1262
+ }
1263
+ }
1264
+
1265
+ return Clock;
1266
+ };
1267
+
1268
+ getJasmineRequireObj().DelayedFunctionScheduler = function() {
1269
+ function DelayedFunctionScheduler() {
1270
+ var self = this;
1271
+ var scheduledLookup = [];
1272
+ var scheduledFunctions = {};
1273
+ var currentTime = 0;
1274
+ var delayedFnCount = 0;
1275
+
1276
+ self.tick = function(millis) {
1277
+ millis = millis || 0;
1278
+ var endTime = currentTime + millis;
1279
+
1280
+ runScheduledFunctions(endTime);
1281
+ currentTime = endTime;
1282
+ };
1283
+
1284
+ self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
1285
+ var f;
1286
+ if (typeof(funcToCall) === 'string') {
1287
+ /* jshint evil: true */
1288
+ f = function() { return eval(funcToCall); };
1289
+ /* jshint evil: false */
1290
+ } else {
1291
+ f = funcToCall;
1292
+ }
1293
+
1294
+ millis = millis || 0;
1295
+ timeoutKey = timeoutKey || ++delayedFnCount;
1296
+ runAtMillis = runAtMillis || (currentTime + millis);
1297
+
1298
+ var funcToSchedule = {
1299
+ runAtMillis: runAtMillis,
1300
+ funcToCall: f,
1301
+ recurring: recurring,
1302
+ params: params,
1303
+ timeoutKey: timeoutKey,
1304
+ millis: millis
1305
+ };
1306
+
1307
+ if (runAtMillis in scheduledFunctions) {
1308
+ scheduledFunctions[runAtMillis].push(funcToSchedule);
1309
+ } else {
1310
+ scheduledFunctions[runAtMillis] = [funcToSchedule];
1311
+ scheduledLookup.push(runAtMillis);
1312
+ scheduledLookup.sort(function (a, b) {
1313
+ return a - b;
1314
+ });
1315
+ }
1316
+
1317
+ return timeoutKey;
1318
+ };
1319
+
1320
+ self.removeFunctionWithId = function(timeoutKey) {
1321
+ for (var runAtMillis in scheduledFunctions) {
1322
+ var funcs = scheduledFunctions[runAtMillis];
1323
+ var i = indexOfFirstToPass(funcs, function (func) {
1324
+ return func.timeoutKey === timeoutKey;
1325
+ });
1326
+
1327
+ if (i > -1) {
1328
+ if (funcs.length === 1) {
1329
+ delete scheduledFunctions[runAtMillis];
1330
+ deleteFromLookup(runAtMillis);
1331
+ } else {
1332
+ funcs.splice(i, 1);
1333
+ }
1334
+
1335
+ // intervals get rescheduled when executed, so there's never more
1336
+ // than a single scheduled function with a given timeoutKey
1337
+ break;
1338
+ }
1339
+ }
1340
+ };
1341
+
1342
+ return self;
1343
+
1344
+ function indexOfFirstToPass(array, testFn) {
1345
+ var index = -1;
1346
+
1347
+ for (var i = 0; i < array.length; ++i) {
1348
+ if (testFn(array[i])) {
1349
+ index = i;
1350
+ break;
1351
+ }
1352
+ }
1353
+
1354
+ return index;
1355
+ }
1356
+
1357
+ function deleteFromLookup(key) {
1358
+ var value = Number(key);
1359
+ var i = indexOfFirstToPass(scheduledLookup, function (millis) {
1360
+ return millis === value;
1361
+ });
1362
+
1363
+ if (i > -1) {
1364
+ scheduledLookup.splice(i, 1);
1365
+ }
1366
+ }
1367
+
1368
+ function reschedule(scheduledFn) {
1369
+ self.scheduleFunction(scheduledFn.funcToCall,
1370
+ scheduledFn.millis,
1371
+ scheduledFn.params,
1372
+ true,
1373
+ scheduledFn.timeoutKey,
1374
+ scheduledFn.runAtMillis + scheduledFn.millis);
1375
+ }
1376
+
1377
+ function forEachFunction(funcsToRun, callback) {
1378
+ for (var i = 0; i < funcsToRun.length; ++i) {
1379
+ callback(funcsToRun[i]);
1380
+ }
1381
+ }
1382
+
1383
+ function runScheduledFunctions(endTime) {
1384
+ if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
1385
+ return;
1386
+ }
1387
+
1388
+ do {
1389
+ currentTime = scheduledLookup.shift();
1390
+
1391
+ var funcsToRun = scheduledFunctions[currentTime];
1392
+ delete scheduledFunctions[currentTime];
1393
+
1394
+ forEachFunction(funcsToRun, function(funcToRun) {
1395
+ if (funcToRun.recurring) {
1396
+ reschedule(funcToRun);
1397
+ }
1398
+ });
1399
+
1400
+ forEachFunction(funcsToRun, function(funcToRun) {
1401
+ funcToRun.funcToCall.apply(null, funcToRun.params || []);
1402
+ });
1403
+ } while (scheduledLookup.length > 0 &&
1404
+ // checking first if we're out of time prevents setTimeout(0)
1405
+ // scheduled in a funcToRun from forcing an extra iteration
1406
+ currentTime !== endTime &&
1407
+ scheduledLookup[0] <= endTime);
1408
+ }
1409
+ }
1410
+
1411
+ return DelayedFunctionScheduler;
1412
+ };
1413
+
1414
+ getJasmineRequireObj().ExceptionFormatter = function() {
1415
+ function ExceptionFormatter() {
1416
+ this.message = function(error) {
1417
+ var message = '';
1418
+
1419
+ if (error.name && error.message) {
1420
+ message += error.name + ': ' + error.message;
1421
+ } else {
1422
+ message += error.toString() + ' thrown';
1423
+ }
1424
+
1425
+ if (error.fileName || error.sourceURL) {
1426
+ message += ' in ' + (error.fileName || error.sourceURL);
1427
+ }
1428
+
1429
+ if (error.line || error.lineNumber) {
1430
+ message += ' (line ' + (error.line || error.lineNumber) + ')';
1431
+ }
1432
+
1433
+ return message;
1434
+ };
1435
+
1436
+ this.stack = function(error) {
1437
+ return error ? error.stack : null;
1438
+ };
1439
+ }
1440
+
1441
+ return ExceptionFormatter;
1442
+ };
1443
+
1444
+ getJasmineRequireObj().Expectation = function() {
1445
+
1446
+ function Expectation(options) {
1447
+ this.util = options.util || { buildFailureMessage: function() {} };
1448
+ this.customEqualityTesters = options.customEqualityTesters || [];
1449
+ this.actual = options.actual;
1450
+ this.addExpectationResult = options.addExpectationResult || function(){};
1451
+ this.isNot = options.isNot;
1452
+
1453
+ var customMatchers = options.customMatchers || {};
1454
+ for (var matcherName in customMatchers) {
1455
+ this[matcherName] = Expectation.prototype.wrapCompare(matcherName, customMatchers[matcherName]);
1456
+ }
1457
+ }
1458
+
1459
+ Expectation.prototype.wrapCompare = function(name, matcherFactory) {
1460
+ return function() {
1461
+ var args = Array.prototype.slice.call(arguments, 0),
1462
+ expected = args.slice(0),
1463
+ message = '';
1464
+
1465
+ args.unshift(this.actual);
1466
+
1467
+ var matcher = matcherFactory(this.util, this.customEqualityTesters),
1468
+ matcherCompare = matcher.compare;
1469
+
1470
+ function defaultNegativeCompare() {
1471
+ var result = matcher.compare.apply(null, args);
1472
+ result.pass = !result.pass;
1473
+ return result;
1474
+ }
1475
+
1476
+ if (this.isNot) {
1477
+ matcherCompare = matcher.negativeCompare || defaultNegativeCompare;
1478
+ }
1479
+
1480
+ var result = matcherCompare.apply(null, args);
1481
+
1482
+ if (!result.pass) {
1483
+ if (!result.message) {
1484
+ args.unshift(this.isNot);
1485
+ args.unshift(name);
1486
+ message = this.util.buildFailureMessage.apply(null, args);
1487
+ } else {
1488
+ if (Object.prototype.toString.apply(result.message) === '[object Function]') {
1489
+ message = result.message();
1490
+ } else {
1491
+ message = result.message;
1492
+ }
1493
+ }
1494
+ }
1495
+
1496
+ if (expected.length == 1) {
1497
+ expected = expected[0];
1498
+ }
1499
+
1500
+ // TODO: how many of these params are needed?
1501
+ this.addExpectationResult(
1502
+ result.pass,
1503
+ {
1504
+ matcherName: name,
1505
+ passed: result.pass,
1506
+ message: message,
1507
+ actual: this.actual,
1508
+ expected: expected // TODO: this may need to be arrayified/sliced
1509
+ }
1510
+ );
1511
+ };
1512
+ };
1513
+
1514
+ Expectation.addCoreMatchers = function(matchers) {
1515
+ var prototype = Expectation.prototype;
1516
+ for (var matcherName in matchers) {
1517
+ var matcher = matchers[matcherName];
1518
+ prototype[matcherName] = prototype.wrapCompare(matcherName, matcher);
1519
+ }
1520
+ };
1521
+
1522
+ Expectation.Factory = function(options) {
1523
+ options = options || {};
1524
+
1525
+ var expect = new Expectation(options);
1526
+
1527
+ // TODO: this would be nice as its own Object - NegativeExpectation
1528
+ // TODO: copy instead of mutate options
1529
+ options.isNot = true;
1530
+ expect.not = new Expectation(options);
1531
+
1532
+ return expect;
1533
+ };
1534
+
1535
+ return Expectation;
1536
+ };
1537
+
1538
+ //TODO: expectation result may make more sense as a presentation of an expectation.
1539
+ getJasmineRequireObj().buildExpectationResult = function() {
1540
+ function buildExpectationResult(options) {
1541
+ var messageFormatter = options.messageFormatter || function() {},
1542
+ stackFormatter = options.stackFormatter || function() {};
1543
+
1544
+ var result = {
1545
+ matcherName: options.matcherName,
1546
+ message: message(),
1547
+ stack: stack(),
1548
+ passed: options.passed
1549
+ };
1550
+
1551
+ if(!result.passed) {
1552
+ result.expected = options.expected;
1553
+ result.actual = options.actual;
1554
+ }
1555
+
1556
+ return result;
1557
+
1558
+ function message() {
1559
+ if (options.passed) {
1560
+ return 'Passed.';
1561
+ } else if (options.message) {
1562
+ return options.message;
1563
+ } else if (options.error) {
1564
+ return messageFormatter(options.error);
1565
+ }
1566
+ return '';
1567
+ }
1568
+
1569
+ function stack() {
1570
+ if (options.passed) {
1571
+ return '';
1572
+ }
1573
+
1574
+ var error = options.error;
1575
+ if (!error) {
1576
+ try {
1577
+ throw new Error(message());
1578
+ } catch (e) {
1579
+ error = e;
1580
+ }
1581
+ }
1582
+ return stackFormatter(error);
1583
+ }
1584
+ }
1585
+
1586
+ return buildExpectationResult;
1587
+ };
1588
+
1589
+ getJasmineRequireObj().MockDate = function() {
1590
+ function MockDate(global) {
1591
+ var self = this;
1592
+ var currentTime = 0;
1593
+
1594
+ if (!global || !global.Date) {
1595
+ self.install = function() {};
1596
+ self.tick = function() {};
1597
+ self.uninstall = function() {};
1598
+ return self;
1599
+ }
1600
+
1601
+ var GlobalDate = global.Date;
1602
+
1603
+ self.install = function(mockDate) {
1604
+ if (mockDate instanceof GlobalDate) {
1605
+ currentTime = mockDate.getTime();
1606
+ } else {
1607
+ currentTime = new GlobalDate().getTime();
1608
+ }
1609
+
1610
+ global.Date = FakeDate;
1611
+ };
1612
+
1613
+ self.tick = function(millis) {
1614
+ millis = millis || 0;
1615
+ currentTime = currentTime + millis;
1616
+ };
1617
+
1618
+ self.uninstall = function() {
1619
+ currentTime = 0;
1620
+ global.Date = GlobalDate;
1621
+ };
1622
+
1623
+ createDateProperties();
1624
+
1625
+ return self;
1626
+
1627
+ function FakeDate() {
1628
+ switch(arguments.length) {
1629
+ case 0:
1630
+ return new GlobalDate(currentTime);
1631
+ case 1:
1632
+ return new GlobalDate(arguments[0]);
1633
+ case 2:
1634
+ return new GlobalDate(arguments[0], arguments[1]);
1635
+ case 3:
1636
+ return new GlobalDate(arguments[0], arguments[1], arguments[2]);
1637
+ case 4:
1638
+ return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]);
1639
+ case 5:
1640
+ return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
1641
+ arguments[4]);
1642
+ case 6:
1643
+ return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
1644
+ arguments[4], arguments[5]);
1645
+ default:
1646
+ return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
1647
+ arguments[4], arguments[5], arguments[6]);
1648
+ }
1649
+ }
1650
+
1651
+ function createDateProperties() {
1652
+ FakeDate.prototype = GlobalDate.prototype;
1653
+
1654
+ FakeDate.now = function() {
1655
+ if (GlobalDate.now) {
1656
+ return currentTime;
1657
+ } else {
1658
+ throw new Error('Browser does not support Date.now()');
1659
+ }
1660
+ };
1661
+
1662
+ FakeDate.toSource = GlobalDate.toSource;
1663
+ FakeDate.toString = GlobalDate.toString;
1664
+ FakeDate.parse = GlobalDate.parse;
1665
+ FakeDate.UTC = GlobalDate.UTC;
1666
+ }
1667
+ }
1668
+
1669
+ return MockDate;
1670
+ };
1671
+
1672
+ getJasmineRequireObj().pp = function(j$) {
1673
+
1674
+ function PrettyPrinter() {
1675
+ this.ppNestLevel_ = 0;
1676
+ this.seen = [];
1677
+ }
1678
+
1679
+ PrettyPrinter.prototype.format = function(value) {
1680
+ this.ppNestLevel_++;
1681
+ try {
1682
+ if (j$.util.isUndefined(value)) {
1683
+ this.emitScalar('undefined');
1684
+ } else if (value === null) {
1685
+ this.emitScalar('null');
1686
+ } else if (value === 0 && 1/value === -Infinity) {
1687
+ this.emitScalar('-0');
1688
+ } else if (value === j$.getGlobal()) {
1689
+ this.emitScalar('<global>');
1690
+ } else if (value.jasmineToString) {
1691
+ this.emitScalar(value.jasmineToString());
1692
+ } else if (typeof value === 'string') {
1693
+ this.emitString(value);
1694
+ } else if (j$.isSpy(value)) {
1695
+ this.emitScalar('spy on ' + value.and.identity());
1696
+ } else if (value instanceof RegExp) {
1697
+ this.emitScalar(value.toString());
1698
+ } else if (typeof value === 'function') {
1699
+ this.emitScalar('Function');
1700
+ } else if (typeof value.nodeType === 'number') {
1701
+ this.emitScalar('HTMLNode');
1702
+ } else if (value instanceof Date) {
1703
+ this.emitScalar('Date(' + value + ')');
1704
+ } else if (value.toString && typeof value === 'object' && !(value instanceof Array) && value.toString !== Object.prototype.toString) {
1705
+ this.emitScalar(value.toString());
1706
+ } else if (j$.util.arrayContains(this.seen, value)) {
1707
+ this.emitScalar('<circular reference: ' + (j$.isArray_(value) ? 'Array' : 'Object') + '>');
1708
+ } else if (j$.isArray_(value) || j$.isA_('Object', value)) {
1709
+ this.seen.push(value);
1710
+ if (j$.isArray_(value)) {
1711
+ this.emitArray(value);
1712
+ } else {
1713
+ this.emitObject(value);
1714
+ }
1715
+ this.seen.pop();
1716
+ } else {
1717
+ this.emitScalar(value.toString());
1718
+ }
1719
+ } finally {
1720
+ this.ppNestLevel_--;
1721
+ }
1722
+ };
1723
+
1724
+ PrettyPrinter.prototype.iterateObject = function(obj, fn) {
1725
+ for (var property in obj) {
1726
+ if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; }
1727
+ fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) &&
1728
+ obj.__lookupGetter__(property) !== null) : false);
1729
+ }
1730
+ };
1731
+
1732
+ PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_;
1733
+ PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
1734
+ PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
1735
+ PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
1736
+
1737
+ function StringPrettyPrinter() {
1738
+ PrettyPrinter.call(this);
1739
+
1740
+ this.string = '';
1741
+ }
1742
+
1743
+ j$.util.inherit(StringPrettyPrinter, PrettyPrinter);
1744
+
1745
+ StringPrettyPrinter.prototype.emitScalar = function(value) {
1746
+ this.append(value);
1747
+ };
1748
+
1749
+ StringPrettyPrinter.prototype.emitString = function(value) {
1750
+ this.append('\'' + value + '\'');
1751
+ };
1752
+
1753
+ StringPrettyPrinter.prototype.emitArray = function(array) {
1754
+ if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
1755
+ this.append('Array');
1756
+ return;
1757
+ }
1758
+ var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
1759
+ this.append('[ ');
1760
+ for (var i = 0; i < length; i++) {
1761
+ if (i > 0) {
1762
+ this.append(', ');
1763
+ }
1764
+ this.format(array[i]);
1765
+ }
1766
+ if(array.length > length){
1767
+ this.append(', ...');
1768
+ }
1769
+
1770
+ var self = this;
1771
+ var first = array.length === 0;
1772
+ this.iterateObject(array, function(property, isGetter) {
1773
+ if (property.match(/^\d+$/)) {
1774
+ return;
1775
+ }
1776
+
1777
+ if (first) {
1778
+ first = false;
1779
+ } else {
1780
+ self.append(', ');
1781
+ }
1782
+
1783
+ self.formatProperty(array, property, isGetter);
1784
+ });
1785
+
1786
+ this.append(' ]');
1787
+ };
1788
+
1789
+ StringPrettyPrinter.prototype.emitObject = function(obj) {
1790
+ var constructorName = obj.constructor ? j$.fnNameFor(obj.constructor) : 'null';
1791
+ this.append(constructorName);
1792
+
1793
+ if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
1794
+ return;
1795
+ }
1796
+
1797
+ var self = this;
1798
+ this.append('({ ');
1799
+ var first = true;
1800
+
1801
+ this.iterateObject(obj, function(property, isGetter) {
1802
+ if (first) {
1803
+ first = false;
1804
+ } else {
1805
+ self.append(', ');
1806
+ }
1807
+
1808
+ self.formatProperty(obj, property, isGetter);
1809
+ });
1810
+
1811
+ this.append(' })');
1812
+ };
1813
+
1814
+ StringPrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
1815
+ this.append(property);
1816
+ this.append(': ');
1817
+ if (isGetter) {
1818
+ this.append('<getter>');
1819
+ } else {
1820
+ this.format(obj[property]);
1821
+ }
1822
+ };
1823
+
1824
+ StringPrettyPrinter.prototype.append = function(value) {
1825
+ this.string += value;
1826
+ };
1827
+
1828
+ return function(value) {
1829
+ var stringPrettyPrinter = new StringPrettyPrinter();
1830
+ stringPrettyPrinter.format(value);
1831
+ return stringPrettyPrinter.string;
1832
+ };
1833
+ };
1834
+
1835
+ getJasmineRequireObj().QueueRunner = function(j$) {
1836
+
1837
+ function once(fn) {
1838
+ var called = false;
1839
+ return function() {
1840
+ if (!called) {
1841
+ called = true;
1842
+ fn();
1843
+ }
1844
+ };
1845
+ }
1846
+
1847
+ function QueueRunner(attrs) {
1848
+ this.queueableFns = attrs.queueableFns || [];
1849
+ this.onComplete = attrs.onComplete || function() {};
1850
+ this.clearStack = attrs.clearStack || function(fn) {fn();};
1851
+ this.onException = attrs.onException || function() {};
1852
+ this.catchException = attrs.catchException || function() { return true; };
1853
+ this.userContext = attrs.userContext || {};
1854
+ this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
1855
+ this.fail = attrs.fail || function() {};
1856
+ }
1857
+
1858
+ QueueRunner.prototype.execute = function() {
1859
+ this.run(this.queueableFns, 0);
1860
+ };
1861
+
1862
+ QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
1863
+ var length = queueableFns.length,
1864
+ self = this,
1865
+ iterativeIndex;
1866
+
1867
+
1868
+ for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
1869
+ var queueableFn = queueableFns[iterativeIndex];
1870
+ if (queueableFn.fn.length > 0) {
1871
+ attemptAsync(queueableFn);
1872
+ return;
1873
+ } else {
1874
+ attemptSync(queueableFn);
1875
+ }
1876
+ }
1877
+
1878
+ var runnerDone = iterativeIndex >= length;
1879
+
1880
+ if (runnerDone) {
1881
+ this.clearStack(this.onComplete);
1882
+ }
1883
+
1884
+ function attemptSync(queueableFn) {
1885
+ try {
1886
+ queueableFn.fn.call(self.userContext);
1887
+ } catch (e) {
1888
+ handleException(e, queueableFn);
1889
+ }
1890
+ }
1891
+
1892
+ function attemptAsync(queueableFn) {
1893
+ var clearTimeout = function () {
1894
+ Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
1895
+ },
1896
+ next = once(function () {
1897
+ clearTimeout(timeoutId);
1898
+ self.run(queueableFns, iterativeIndex + 1);
1899
+ }),
1900
+ timeoutId;
1901
+
1902
+ next.fail = function() {
1903
+ self.fail.apply(null, arguments);
1904
+ next();
1905
+ };
1906
+
1907
+ if (queueableFn.timeout) {
1908
+ timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() {
1909
+ var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
1910
+ onException(error);
1911
+ next();
1912
+ }, queueableFn.timeout()]]);
1913
+ }
1914
+
1915
+ try {
1916
+ queueableFn.fn.call(self.userContext, next);
1917
+ } catch (e) {
1918
+ handleException(e, queueableFn);
1919
+ next();
1920
+ }
1921
+ }
1922
+
1923
+ function onException(e) {
1924
+ self.onException(e);
1925
+ }
1926
+
1927
+ function handleException(e, queueableFn) {
1928
+ onException(e);
1929
+ if (!self.catchException(e)) {
1930
+ //TODO: set a var when we catch an exception and
1931
+ //use a finally block to close the loop in a nice way..
1932
+ throw e;
1933
+ }
1934
+ }
1935
+ };
1936
+
1937
+ return QueueRunner;
1938
+ };
1939
+
1940
+ getJasmineRequireObj().ReportDispatcher = function() {
1941
+ function ReportDispatcher(methods) {
1942
+
1943
+ var dispatchedMethods = methods || [];
1944
+
1945
+ for (var i = 0; i < dispatchedMethods.length; i++) {
1946
+ var method = dispatchedMethods[i];
1947
+ this[method] = (function(m) {
1948
+ return function() {
1949
+ dispatch(m, arguments);
1950
+ };
1951
+ }(method));
1952
+ }
1953
+
1954
+ var reporters = [];
1955
+
1956
+ this.addReporter = function(reporter) {
1957
+ reporters.push(reporter);
1958
+ };
1959
+
1960
+ return this;
1961
+
1962
+ function dispatch(method, args) {
1963
+ for (var i = 0; i < reporters.length; i++) {
1964
+ var reporter = reporters[i];
1965
+ if (reporter[method]) {
1966
+ reporter[method].apply(reporter, args);
1967
+ }
1968
+ }
1969
+ }
1970
+ }
1971
+
1972
+ return ReportDispatcher;
1973
+ };
1974
+
1975
+
1976
+ getJasmineRequireObj().SpyRegistry = function(j$) {
1977
+
1978
+ function SpyRegistry(options) {
1979
+ options = options || {};
1980
+ var currentSpies = options.currentSpies || function() { return []; };
1981
+
1982
+ this.spyOn = function(obj, methodName) {
1983
+ if (j$.util.isUndefined(obj)) {
1984
+ throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()');
1985
+ }
1986
+
1987
+ if (j$.util.isUndefined(methodName)) {
1988
+ throw new Error('No method name supplied');
1989
+ }
1990
+
1991
+ if (j$.util.isUndefined(obj[methodName])) {
1992
+ throw new Error(methodName + '() method does not exist');
1993
+ }
1994
+
1995
+ if (obj[methodName] && j$.isSpy(obj[methodName])) {
1996
+ //TODO?: should this return the current spy? Downside: may cause user confusion about spy state
1997
+ throw new Error(methodName + ' has already been spied upon');
1998
+ }
1999
+
2000
+ var descriptor;
2001
+ try {
2002
+ descriptor = Object.getOwnPropertyDescriptor(obj, methodName);
2003
+ } catch(e) {
2004
+ // IE 8 doesn't support `definePropery` on non-DOM nodes
2005
+ }
2006
+
2007
+ if (descriptor && !(descriptor.writable || descriptor.set)) {
2008
+ throw new Error(methodName + ' is not declared writable or has no setter');
2009
+ }
2010
+
2011
+ var spy = j$.createSpy(methodName, obj[methodName]);
2012
+
2013
+ currentSpies().push({
2014
+ spy: spy,
2015
+ baseObj: obj,
2016
+ methodName: methodName,
2017
+ originalValue: obj[methodName]
2018
+ });
2019
+
2020
+ obj[methodName] = spy;
2021
+
2022
+ return spy;
2023
+ };
2024
+
2025
+ this.clearSpies = function() {
2026
+ var spies = currentSpies();
2027
+ for (var i = 0; i < spies.length; i++) {
2028
+ var spyEntry = spies[i];
2029
+ spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue;
2030
+ }
2031
+ };
2032
+ }
2033
+
2034
+ return SpyRegistry;
2035
+ };
2036
+
2037
+ getJasmineRequireObj().SpyStrategy = function() {
2038
+
2039
+ function SpyStrategy(options) {
2040
+ options = options || {};
2041
+
2042
+ var identity = options.name || 'unknown',
2043
+ originalFn = options.fn || function() {},
2044
+ getSpy = options.getSpy || function() {},
2045
+ plan = function() {};
2046
+
2047
+ this.identity = function() {
2048
+ return identity;
2049
+ };
2050
+
2051
+ this.exec = function() {
2052
+ return plan.apply(this, arguments);
2053
+ };
2054
+
2055
+ this.callThrough = function() {
2056
+ plan = originalFn;
2057
+ return getSpy();
2058
+ };
2059
+
2060
+ this.returnValue = function(value) {
2061
+ plan = function() {
2062
+ return value;
2063
+ };
2064
+ return getSpy();
2065
+ };
2066
+
2067
+ this.returnValues = function() {
2068
+ var values = Array.prototype.slice.call(arguments);
2069
+ plan = function () {
2070
+ return values.shift();
2071
+ };
2072
+ return getSpy();
2073
+ };
2074
+
2075
+ this.throwError = function(something) {
2076
+ var error = (something instanceof Error) ? something : new Error(something);
2077
+ plan = function() {
2078
+ throw error;
2079
+ };
2080
+ return getSpy();
2081
+ };
2082
+
2083
+ this.callFake = function(fn) {
2084
+ plan = fn;
2085
+ return getSpy();
2086
+ };
2087
+
2088
+ this.stub = function(fn) {
2089
+ plan = function() {};
2090
+ return getSpy();
2091
+ };
2092
+ }
2093
+
2094
+ return SpyStrategy;
2095
+ };
2096
+
2097
+ getJasmineRequireObj().Suite = function(j$) {
2098
+ function Suite(attrs) {
2099
+ this.env = attrs.env;
2100
+ this.id = attrs.id;
2101
+ this.parentSuite = attrs.parentSuite;
2102
+ this.description = attrs.description;
2103
+ this.expectationFactory = attrs.expectationFactory;
2104
+ this.expectationResultFactory = attrs.expectationResultFactory;
2105
+ this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
2106
+
2107
+ this.beforeFns = [];
2108
+ this.afterFns = [];
2109
+ this.beforeAllFns = [];
2110
+ this.afterAllFns = [];
2111
+ this.disabled = false;
2112
+
2113
+ this.children = [];
2114
+
2115
+ this.result = {
2116
+ id: this.id,
2117
+ description: this.description,
2118
+ fullName: this.getFullName(),
2119
+ failedExpectations: []
2120
+ };
2121
+ }
2122
+
2123
+ Suite.prototype.expect = function(actual) {
2124
+ return this.expectationFactory(actual, this);
2125
+ };
2126
+
2127
+ Suite.prototype.getFullName = function() {
2128
+ var fullName = this.description;
2129
+ for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
2130
+ if (parentSuite.parentSuite) {
2131
+ fullName = parentSuite.description + ' ' + fullName;
2132
+ }
2133
+ }
2134
+ return fullName;
2135
+ };
2136
+
2137
+ Suite.prototype.disable = function() {
2138
+ this.disabled = true;
2139
+ };
2140
+
2141
+ Suite.prototype.pend = function(message) {
2142
+ this.markedPending = true;
2143
+ };
2144
+
2145
+ Suite.prototype.beforeEach = function(fn) {
2146
+ this.beforeFns.unshift(fn);
2147
+ };
2148
+
2149
+ Suite.prototype.beforeAll = function(fn) {
2150
+ this.beforeAllFns.push(fn);
2151
+ };
2152
+
2153
+ Suite.prototype.afterEach = function(fn) {
2154
+ this.afterFns.unshift(fn);
2155
+ };
2156
+
2157
+ Suite.prototype.afterAll = function(fn) {
2158
+ this.afterAllFns.push(fn);
2159
+ };
2160
+
2161
+ Suite.prototype.addChild = function(child) {
2162
+ this.children.push(child);
2163
+ };
2164
+
2165
+ Suite.prototype.status = function() {
2166
+ if (this.disabled) {
2167
+ return 'disabled';
2168
+ }
2169
+
2170
+ if (this.markedPending) {
2171
+ return 'pending';
2172
+ }
2173
+
2174
+ if (this.result.failedExpectations.length > 0) {
2175
+ return 'failed';
2176
+ } else {
2177
+ return 'finished';
2178
+ }
2179
+ };
2180
+
2181
+ Suite.prototype.isExecutable = function() {
2182
+ return !this.disabled;
2183
+ };
2184
+
2185
+ Suite.prototype.canBeReentered = function() {
2186
+ return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
2187
+ };
2188
+
2189
+ Suite.prototype.getResult = function() {
2190
+ this.result.status = this.status();
2191
+ return this.result;
2192
+ };
2193
+
2194
+ Suite.prototype.sharedUserContext = function() {
2195
+ if (!this.sharedContext) {
2196
+ this.sharedContext = this.parentSuite ? clone(this.parentSuite.sharedUserContext()) : {};
2197
+ }
2198
+
2199
+ return this.sharedContext;
2200
+ };
2201
+
2202
+ Suite.prototype.clonedSharedUserContext = function() {
2203
+ return clone(this.sharedUserContext());
2204
+ };
2205
+
2206
+ Suite.prototype.onException = function() {
2207
+ if (arguments[0] instanceof j$.errors.ExpectationFailed) {
2208
+ return;
2209
+ }
2210
+
2211
+ if(isAfterAll(this.children)) {
2212
+ var data = {
2213
+ matcherName: '',
2214
+ passed: false,
2215
+ expected: '',
2216
+ actual: '',
2217
+ error: arguments[0]
2218
+ };
2219
+ this.result.failedExpectations.push(this.expectationResultFactory(data));
2220
+ } else {
2221
+ for (var i = 0; i < this.children.length; i++) {
2222
+ var child = this.children[i];
2223
+ child.onException.apply(child, arguments);
2224
+ }
2225
+ }
2226
+ };
2227
+
2228
+ Suite.prototype.addExpectationResult = function () {
2229
+ if(isAfterAll(this.children) && isFailure(arguments)){
2230
+ var data = arguments[1];
2231
+ this.result.failedExpectations.push(this.expectationResultFactory(data));
2232
+ if(this.throwOnExpectationFailure) {
2233
+ throw new j$.errors.ExpectationFailed();
2234
+ }
2235
+ } else {
2236
+ for (var i = 0; i < this.children.length; i++) {
2237
+ var child = this.children[i];
2238
+ try {
2239
+ child.addExpectationResult.apply(child, arguments);
2240
+ } catch(e) {
2241
+ // keep going
2242
+ }
2243
+ }
2244
+ }
2245
+ };
2246
+
2247
+ function isAfterAll(children) {
2248
+ return children && children[0].result.status;
2249
+ }
2250
+
2251
+ function isFailure(args) {
2252
+ return !args[0];
2253
+ }
2254
+
2255
+ function clone(obj) {
2256
+ var clonedObj = {};
2257
+ for (var prop in obj) {
2258
+ if (obj.hasOwnProperty(prop)) {
2259
+ clonedObj[prop] = obj[prop];
2260
+ }
2261
+ }
2262
+
2263
+ return clonedObj;
2264
+ }
2265
+
2266
+ return Suite;
2267
+ };
2268
+
2269
+ if (typeof window == void 0 && typeof exports == 'object') {
2270
+ exports.Suite = jasmineRequire.Suite;
2271
+ }
2272
+
2273
+ getJasmineRequireObj().Timer = function() {
2274
+ var defaultNow = (function(Date) {
2275
+ return function() { return new Date().getTime(); };
2276
+ })(Date);
2277
+
2278
+ function Timer(options) {
2279
+ options = options || {};
2280
+
2281
+ var now = options.now || defaultNow,
2282
+ startTime;
2283
+
2284
+ this.start = function() {
2285
+ startTime = now();
2286
+ };
2287
+
2288
+ this.elapsed = function() {
2289
+ return now() - startTime;
2290
+ };
2291
+ }
2292
+
2293
+ return Timer;
2294
+ };
2295
+
2296
+ getJasmineRequireObj().TreeProcessor = function() {
2297
+ function TreeProcessor(attrs) {
2298
+ var tree = attrs.tree,
2299
+ runnableIds = attrs.runnableIds,
2300
+ queueRunnerFactory = attrs.queueRunnerFactory,
2301
+ nodeStart = attrs.nodeStart || function() {},
2302
+ nodeComplete = attrs.nodeComplete || function() {},
2303
+ orderChildren = attrs.orderChildren || function(node) { return node.children; },
2304
+ stats = { valid: true },
2305
+ processed = false,
2306
+ defaultMin = Infinity,
2307
+ defaultMax = 1 - Infinity;
2308
+
2309
+ this.processTree = function() {
2310
+ processNode(tree, false);
2311
+ processed = true;
2312
+ return stats;
2313
+ };
2314
+
2315
+ this.execute = function(done) {
2316
+ if (!processed) {
2317
+ this.processTree();
2318
+ }
2319
+
2320
+ if (!stats.valid) {
2321
+ throw 'invalid order';
2322
+ }
2323
+
2324
+ var childFns = wrapChildren(tree, 0);
2325
+
2326
+ queueRunnerFactory({
2327
+ queueableFns: childFns,
2328
+ userContext: tree.sharedUserContext(),
2329
+ onException: function() {
2330
+ tree.onException.apply(tree, arguments);
2331
+ },
2332
+ onComplete: done
2333
+ });
2334
+ };
2335
+
2336
+ function runnableIndex(id) {
2337
+ for (var i = 0; i < runnableIds.length; i++) {
2338
+ if (runnableIds[i] === id) {
2339
+ return i;
2340
+ }
2341
+ }
2342
+ }
2343
+
2344
+ function processNode(node, parentEnabled) {
2345
+ var executableIndex = runnableIndex(node.id);
2346
+
2347
+ if (executableIndex !== undefined) {
2348
+ parentEnabled = true;
2349
+ }
2350
+
2351
+ parentEnabled = parentEnabled && node.isExecutable();
2352
+
2353
+ if (!node.children) {
2354
+ stats[node.id] = {
2355
+ executable: parentEnabled && node.isExecutable(),
2356
+ segments: [{
2357
+ index: 0,
2358
+ owner: node,
2359
+ nodes: [node],
2360
+ min: startingMin(executableIndex),
2361
+ max: startingMax(executableIndex)
2362
+ }]
2363
+ };
2364
+ } else {
2365
+ var hasExecutableChild = false;
2366
+
2367
+ var orderedChildren = orderChildren(node);
2368
+
2369
+ for (var i = 0; i < orderedChildren.length; i++) {
2370
+ var child = orderedChildren[i];
2371
+
2372
+ processNode(child, parentEnabled);
2373
+
2374
+ if (!stats.valid) {
2375
+ return;
2376
+ }
2377
+
2378
+ var childStats = stats[child.id];
2379
+
2380
+ hasExecutableChild = hasExecutableChild || childStats.executable;
2381
+ }
2382
+
2383
+ stats[node.id] = {
2384
+ executable: hasExecutableChild
2385
+ };
2386
+
2387
+ segmentChildren(node, orderedChildren, stats[node.id], executableIndex);
2388
+
2389
+ if (!node.canBeReentered() && stats[node.id].segments.length > 1) {
2390
+ stats = { valid: false };
2391
+ }
2392
+ }
2393
+ }
2394
+
2395
+ function startingMin(executableIndex) {
2396
+ return executableIndex === undefined ? defaultMin : executableIndex;
2397
+ }
2398
+
2399
+ function startingMax(executableIndex) {
2400
+ return executableIndex === undefined ? defaultMax : executableIndex;
2401
+ }
2402
+
2403
+ function segmentChildren(node, orderedChildren, nodeStats, executableIndex) {
2404
+ var currentSegment = { index: 0, owner: node, nodes: [], min: startingMin(executableIndex), max: startingMax(executableIndex) },
2405
+ result = [currentSegment],
2406
+ lastMax = defaultMax,
2407
+ orderedChildSegments = orderChildSegments(orderedChildren);
2408
+
2409
+ function isSegmentBoundary(minIndex) {
2410
+ return lastMax !== defaultMax && minIndex !== defaultMin && lastMax < minIndex - 1;
2411
+ }
2412
+
2413
+ for (var i = 0; i < orderedChildSegments.length; i++) {
2414
+ var childSegment = orderedChildSegments[i],
2415
+ maxIndex = childSegment.max,
2416
+ minIndex = childSegment.min;
2417
+
2418
+ if (isSegmentBoundary(minIndex)) {
2419
+ currentSegment = {index: result.length, owner: node, nodes: [], min: defaultMin, max: defaultMax};
2420
+ result.push(currentSegment);
2421
+ }
2422
+
2423
+ currentSegment.nodes.push(childSegment);
2424
+ currentSegment.min = Math.min(currentSegment.min, minIndex);
2425
+ currentSegment.max = Math.max(currentSegment.max, maxIndex);
2426
+ lastMax = maxIndex;
2427
+ }
2428
+
2429
+ nodeStats.segments = result;
2430
+ }
2431
+
2432
+ function orderChildSegments(children) {
2433
+ var specifiedOrder = [],
2434
+ unspecifiedOrder = [];
2435
+
2436
+ for (var i = 0; i < children.length; i++) {
2437
+ var child = children[i],
2438
+ segments = stats[child.id].segments;
2439
+
2440
+ for (var j = 0; j < segments.length; j++) {
2441
+ var seg = segments[j];
2442
+
2443
+ if (seg.min === defaultMin) {
2444
+ unspecifiedOrder.push(seg);
2445
+ } else {
2446
+ specifiedOrder.push(seg);
2447
+ }
2448
+ }
2449
+ }
2450
+
2451
+ specifiedOrder.sort(function(a, b) {
2452
+ return a.min - b.min;
2453
+ });
2454
+
2455
+ return specifiedOrder.concat(unspecifiedOrder);
2456
+ }
2457
+
2458
+ function executeNode(node, segmentNumber) {
2459
+ if (node.children) {
2460
+ return {
2461
+ fn: function(done) {
2462
+ nodeStart(node);
2463
+
2464
+ queueRunnerFactory({
2465
+ onComplete: function() {
2466
+ nodeComplete(node, node.getResult());
2467
+ done();
2468
+ },
2469
+ queueableFns: wrapChildren(node, segmentNumber),
2470
+ userContext: node.sharedUserContext(),
2471
+ onException: function() {
2472
+ node.onException.apply(node, arguments);
2473
+ }
2474
+ });
2475
+ }
2476
+ };
2477
+ } else {
2478
+ return {
2479
+ fn: function(done) { node.execute(done, stats[node.id].executable); }
2480
+ };
2481
+ }
2482
+ }
2483
+
2484
+ function wrapChildren(node, segmentNumber) {
2485
+ var result = [],
2486
+ segmentChildren = stats[node.id].segments[segmentNumber].nodes;
2487
+
2488
+ for (var i = 0; i < segmentChildren.length; i++) {
2489
+ result.push(executeNode(segmentChildren[i].owner, segmentChildren[i].index));
2490
+ }
2491
+
2492
+ if (!stats[node.id].executable) {
2493
+ return result;
2494
+ }
2495
+
2496
+ return node.beforeAllFns.concat(result).concat(node.afterAllFns);
2497
+ }
2498
+ }
2499
+
2500
+ return TreeProcessor;
2501
+ };
2502
+
2503
+ getJasmineRequireObj().Any = function(j$) {
2504
+
2505
+ function Any(expectedObject) {
2506
+ if (typeof expectedObject === 'undefined') {
2507
+ throw new TypeError(
2508
+ 'jasmine.any() expects to be passed a constructor function. ' +
2509
+ 'Please pass one or use jasmine.anything() to match any object.'
2510
+ );
2511
+ }
2512
+ this.expectedObject = expectedObject;
2513
+ }
2514
+
2515
+ Any.prototype.asymmetricMatch = function(other) {
2516
+ if (this.expectedObject == String) {
2517
+ return typeof other == 'string' || other instanceof String;
2518
+ }
2519
+
2520
+ if (this.expectedObject == Number) {
2521
+ return typeof other == 'number' || other instanceof Number;
2522
+ }
2523
+
2524
+ if (this.expectedObject == Function) {
2525
+ return typeof other == 'function' || other instanceof Function;
2526
+ }
2527
+
2528
+ if (this.expectedObject == Object) {
2529
+ return typeof other == 'object';
2530
+ }
2531
+
2532
+ if (this.expectedObject == Boolean) {
2533
+ return typeof other == 'boolean';
2534
+ }
2535
+
2536
+ return other instanceof this.expectedObject;
2537
+ };
2538
+
2539
+ Any.prototype.jasmineToString = function() {
2540
+ return '<jasmine.any(' + j$.fnNameFor(this.expectedObject) + ')>';
2541
+ };
2542
+
2543
+ return Any;
2544
+ };
2545
+
2546
+ getJasmineRequireObj().Anything = function(j$) {
2547
+
2548
+ function Anything() {}
2549
+
2550
+ Anything.prototype.asymmetricMatch = function(other) {
2551
+ return !j$.util.isUndefined(other) && other !== null;
2552
+ };
2553
+
2554
+ Anything.prototype.jasmineToString = function() {
2555
+ return '<jasmine.anything>';
2556
+ };
2557
+
2558
+ return Anything;
2559
+ };
2560
+
2561
+ getJasmineRequireObj().ArrayContaining = function(j$) {
2562
+ function ArrayContaining(sample) {
2563
+ this.sample = sample;
2564
+ }
2565
+
2566
+ ArrayContaining.prototype.asymmetricMatch = function(other) {
2567
+ var className = Object.prototype.toString.call(this.sample);
2568
+ if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); }
2569
+
2570
+ for (var i = 0; i < this.sample.length; i++) {
2571
+ var item = this.sample[i];
2572
+ if (!j$.matchersUtil.contains(other, item)) {
2573
+ return false;
2574
+ }
2575
+ }
2576
+
2577
+ return true;
2578
+ };
2579
+
2580
+ ArrayContaining.prototype.jasmineToString = function () {
2581
+ return '<jasmine.arrayContaining(' + jasmine.pp(this.sample) +')>';
2582
+ };
2583
+
2584
+ return ArrayContaining;
2585
+ };
2586
+
2587
+ getJasmineRequireObj().ObjectContaining = function(j$) {
2588
+
2589
+ function ObjectContaining(sample) {
2590
+ this.sample = sample;
2591
+ }
2592
+
2593
+ function getPrototype(obj) {
2594
+ if (Object.getPrototypeOf) {
2595
+ return Object.getPrototypeOf(obj);
2596
+ }
2597
+
2598
+ if (obj.constructor.prototype == obj) {
2599
+ return null;
2600
+ }
2601
+
2602
+ return obj.constructor.prototype;
2603
+ }
2604
+
2605
+ function hasProperty(obj, property) {
2606
+ if (!obj) {
2607
+ return false;
2608
+ }
2609
+
2610
+ if (Object.prototype.hasOwnProperty.call(obj, property)) {
2611
+ return true;
2612
+ }
2613
+
2614
+ return hasProperty(getPrototype(obj), property);
2615
+ }
2616
+
2617
+ ObjectContaining.prototype.asymmetricMatch = function(other) {
2618
+ if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
2619
+
2620
+ for (var property in this.sample) {
2621
+ if (!hasProperty(other, property) ||
2622
+ !j$.matchersUtil.equals(this.sample[property], other[property])) {
2623
+ return false;
2624
+ }
2625
+ }
2626
+
2627
+ return true;
2628
+ };
2629
+
2630
+ ObjectContaining.prototype.jasmineToString = function() {
2631
+ return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
2632
+ };
2633
+
2634
+ return ObjectContaining;
2635
+ };
2636
+
2637
+ getJasmineRequireObj().StringMatching = function(j$) {
2638
+
2639
+ function StringMatching(expected) {
2640
+ if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
2641
+ throw new Error('Expected is not a String or a RegExp');
2642
+ }
2643
+
2644
+ this.regexp = new RegExp(expected);
2645
+ }
2646
+
2647
+ StringMatching.prototype.asymmetricMatch = function(other) {
2648
+ return this.regexp.test(other);
2649
+ };
2650
+
2651
+ StringMatching.prototype.jasmineToString = function() {
2652
+ return '<jasmine.stringMatching(' + this.regexp + ')>';
2653
+ };
2654
+
2655
+ return StringMatching;
2656
+ };
2657
+
2658
+ getJasmineRequireObj().errors = function() {
2659
+ function ExpectationFailed() {}
2660
+
2661
+ ExpectationFailed.prototype = new Error();
2662
+ ExpectationFailed.prototype.constructor = ExpectationFailed;
2663
+
2664
+ return {
2665
+ ExpectationFailed: ExpectationFailed
2666
+ };
2667
+ };
2668
+ getJasmineRequireObj().matchersUtil = function(j$) {
2669
+ // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter?
2670
+
2671
+ return {
2672
+ equals: function(a, b, customTesters) {
2673
+ customTesters = customTesters || [];
2674
+
2675
+ return eq(a, b, [], [], customTesters);
2676
+ },
2677
+
2678
+ contains: function(haystack, needle, customTesters) {
2679
+ customTesters = customTesters || [];
2680
+
2681
+ if ((Object.prototype.toString.apply(haystack) === '[object Array]') ||
2682
+ (!!haystack && !haystack.indexOf))
2683
+ {
2684
+ for (var i = 0; i < haystack.length; i++) {
2685
+ if (eq(haystack[i], needle, [], [], customTesters)) {
2686
+ return true;
2687
+ }
2688
+ }
2689
+ return false;
2690
+ }
2691
+
2692
+ return !!haystack && haystack.indexOf(needle) >= 0;
2693
+ },
2694
+
2695
+ buildFailureMessage: function() {
2696
+ var args = Array.prototype.slice.call(arguments, 0),
2697
+ matcherName = args[0],
2698
+ isNot = args[1],
2699
+ actual = args[2],
2700
+ expected = args.slice(3),
2701
+ englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
2702
+
2703
+ var message = 'Expected ' +
2704
+ j$.pp(actual) +
2705
+ (isNot ? ' not ' : ' ') +
2706
+ englishyPredicate;
2707
+
2708
+ if (expected.length > 0) {
2709
+ for (var i = 0; i < expected.length; i++) {
2710
+ if (i > 0) {
2711
+ message += ',';
2712
+ }
2713
+ message += ' ' + j$.pp(expected[i]);
2714
+ }
2715
+ }
2716
+
2717
+ return message + '.';
2718
+ }
2719
+ };
2720
+
2721
+ function isAsymmetric(obj) {
2722
+ return obj && j$.isA_('Function', obj.asymmetricMatch);
2723
+ }
2724
+
2725
+ function asymmetricMatch(a, b) {
2726
+ var asymmetricA = isAsymmetric(a),
2727
+ asymmetricB = isAsymmetric(b);
2728
+
2729
+ if (asymmetricA && asymmetricB) {
2730
+ return undefined;
2731
+ }
2732
+
2733
+ if (asymmetricA) {
2734
+ return a.asymmetricMatch(b);
2735
+ }
2736
+
2737
+ if (asymmetricB) {
2738
+ return b.asymmetricMatch(a);
2739
+ }
2740
+ }
2741
+
2742
+ // Equality function lovingly adapted from isEqual in
2743
+ // [Underscore](http://underscorejs.org)
2744
+ function eq(a, b, aStack, bStack, customTesters) {
2745
+ var result = true;
2746
+
2747
+ var asymmetricResult = asymmetricMatch(a, b);
2748
+ if (!j$.util.isUndefined(asymmetricResult)) {
2749
+ return asymmetricResult;
2750
+ }
2751
+
2752
+ for (var i = 0; i < customTesters.length; i++) {
2753
+ var customTesterResult = customTesters[i](a, b);
2754
+ if (!j$.util.isUndefined(customTesterResult)) {
2755
+ return customTesterResult;
2756
+ }
2757
+ }
2758
+
2759
+ if (a instanceof Error && b instanceof Error) {
2760
+ return a.message == b.message;
2761
+ }
2762
+
2763
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
2764
+ // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
2765
+ if (a === b) { return a !== 0 || 1 / a == 1 / b; }
2766
+ // A strict comparison is necessary because `null == undefined`.
2767
+ if (a === null || b === null) { return a === b; }
2768
+ var className = Object.prototype.toString.call(a);
2769
+ if (className != Object.prototype.toString.call(b)) { return false; }
2770
+ switch (className) {
2771
+ // Strings, numbers, dates, and booleans are compared by value.
2772
+ case '[object String]':
2773
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
2774
+ // equivalent to `new String("5")`.
2775
+ return a == String(b);
2776
+ case '[object Number]':
2777
+ // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
2778
+ // other numeric values.
2779
+ return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b);
2780
+ case '[object Date]':
2781
+ case '[object Boolean]':
2782
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
2783
+ // millisecond representations. Note that invalid dates with millisecond representations
2784
+ // of `NaN` are not equivalent.
2785
+ return +a == +b;
2786
+ // RegExps are compared by their source patterns and flags.
2787
+ case '[object RegExp]':
2788
+ return a.source == b.source &&
2789
+ a.global == b.global &&
2790
+ a.multiline == b.multiline &&
2791
+ a.ignoreCase == b.ignoreCase;
2792
+ }
2793
+ if (typeof a != 'object' || typeof b != 'object') { return false; }
2794
+
2795
+ var aIsDomNode = j$.isDomNode(a);
2796
+ var bIsDomNode = j$.isDomNode(b);
2797
+ if (aIsDomNode && bIsDomNode) {
2798
+ // At first try to use DOM3 method isEqualNode
2799
+ if (a.isEqualNode) {
2800
+ return a.isEqualNode(b);
2801
+ }
2802
+ // IE8 doesn't support isEqualNode, try to use outerHTML && innerText
2803
+ var aIsElement = a instanceof Element;
2804
+ var bIsElement = b instanceof Element;
2805
+ if (aIsElement && bIsElement) {
2806
+ return a.outerHTML == b.outerHTML;
2807
+ }
2808
+ if (aIsElement || bIsElement) {
2809
+ return false;
2810
+ }
2811
+ return a.innerText == b.innerText && a.textContent == b.textContent;
2812
+ }
2813
+ if (aIsDomNode || bIsDomNode) {
2814
+ return false;
2815
+ }
2816
+
2817
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
2818
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
2819
+ var length = aStack.length;
2820
+ while (length--) {
2821
+ // Linear search. Performance is inversely proportional to the number of
2822
+ // unique nested structures.
2823
+ if (aStack[length] == a) { return bStack[length] == b; }
2824
+ }
2825
+ // Add the first object to the stack of traversed objects.
2826
+ aStack.push(a);
2827
+ bStack.push(b);
2828
+ var size = 0;
2829
+ // Recursively compare objects and arrays.
2830
+ // Compare array lengths to determine if a deep comparison is necessary.
2831
+ if (className == '[object Array]' && a.length !== b.length) {
2832
+ result = false;
2833
+ }
2834
+
2835
+ if (result) {
2836
+ // Objects with different constructors are not equivalent, but `Object`s
2837
+ // or `Array`s from different frames are.
2838
+ if (className !== '[object Array]') {
2839
+ var aCtor = a.constructor, bCtor = b.constructor;
2840
+ if (aCtor !== bCtor && !(isFunction(aCtor) && aCtor instanceof aCtor &&
2841
+ isFunction(bCtor) && bCtor instanceof bCtor)) {
2842
+ return false;
2843
+ }
2844
+ }
2845
+ // Deep compare objects.
2846
+ for (var key in a) {
2847
+ if (has(a, key)) {
2848
+ // Count the expected number of properties.
2849
+ size++;
2850
+ // Deep compare each member.
2851
+ if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; }
2852
+ }
2853
+ }
2854
+ // Ensure that both objects contain the same number of properties.
2855
+ if (result) {
2856
+ for (key in b) {
2857
+ if (has(b, key) && !(size--)) { break; }
2858
+ }
2859
+ result = !size;
2860
+ }
2861
+ }
2862
+ // Remove the first object from the stack of traversed objects.
2863
+ aStack.pop();
2864
+ bStack.pop();
2865
+
2866
+ return result;
2867
+
2868
+ function has(obj, key) {
2869
+ return Object.prototype.hasOwnProperty.call(obj, key);
2870
+ }
2871
+
2872
+ function isFunction(obj) {
2873
+ return typeof obj === 'function';
2874
+ }
2875
+ }
2876
+ };
2877
+
2878
+ getJasmineRequireObj().toBe = function() {
2879
+ function toBe() {
2880
+ return {
2881
+ compare: function(actual, expected) {
2882
+ return {
2883
+ pass: actual === expected
2884
+ };
2885
+ }
2886
+ };
2887
+ }
2888
+
2889
+ return toBe;
2890
+ };
2891
+
2892
+ getJasmineRequireObj().toBeCloseTo = function() {
2893
+
2894
+ function toBeCloseTo() {
2895
+ return {
2896
+ compare: function(actual, expected, precision) {
2897
+ if (precision !== 0) {
2898
+ precision = precision || 2;
2899
+ }
2900
+
2901
+ return {
2902
+ pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2)
2903
+ };
2904
+ }
2905
+ };
2906
+ }
2907
+
2908
+ return toBeCloseTo;
2909
+ };
2910
+
2911
+ getJasmineRequireObj().toBeDefined = function() {
2912
+ function toBeDefined() {
2913
+ return {
2914
+ compare: function(actual) {
2915
+ return {
2916
+ pass: (void 0 !== actual)
2917
+ };
2918
+ }
2919
+ };
2920
+ }
2921
+
2922
+ return toBeDefined;
2923
+ };
2924
+
2925
+ getJasmineRequireObj().toBeFalsy = function() {
2926
+ function toBeFalsy() {
2927
+ return {
2928
+ compare: function(actual) {
2929
+ return {
2930
+ pass: !!!actual
2931
+ };
2932
+ }
2933
+ };
2934
+ }
2935
+
2936
+ return toBeFalsy;
2937
+ };
2938
+
2939
+ getJasmineRequireObj().toBeGreaterThan = function() {
2940
+
2941
+ function toBeGreaterThan() {
2942
+ return {
2943
+ compare: function(actual, expected) {
2944
+ return {
2945
+ pass: actual > expected
2946
+ };
2947
+ }
2948
+ };
2949
+ }
2950
+
2951
+ return toBeGreaterThan;
2952
+ };
2953
+
2954
+
2955
+ getJasmineRequireObj().toBeLessThan = function() {
2956
+ function toBeLessThan() {
2957
+ return {
2958
+
2959
+ compare: function(actual, expected) {
2960
+ return {
2961
+ pass: actual < expected
2962
+ };
2963
+ }
2964
+ };
2965
+ }
2966
+
2967
+ return toBeLessThan;
2968
+ };
2969
+ getJasmineRequireObj().toBeNaN = function(j$) {
2970
+
2971
+ function toBeNaN() {
2972
+ return {
2973
+ compare: function(actual) {
2974
+ var result = {
2975
+ pass: (actual !== actual)
2976
+ };
2977
+
2978
+ if (result.pass) {
2979
+ result.message = 'Expected actual not to be NaN.';
2980
+ } else {
2981
+ result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; };
2982
+ }
2983
+
2984
+ return result;
2985
+ }
2986
+ };
2987
+ }
2988
+
2989
+ return toBeNaN;
2990
+ };
2991
+
2992
+ getJasmineRequireObj().toBeNull = function() {
2993
+
2994
+ function toBeNull() {
2995
+ return {
2996
+ compare: function(actual) {
2997
+ return {
2998
+ pass: actual === null
2999
+ };
3000
+ }
3001
+ };
3002
+ }
3003
+
3004
+ return toBeNull;
3005
+ };
3006
+
3007
+ getJasmineRequireObj().toBeTruthy = function() {
3008
+
3009
+ function toBeTruthy() {
3010
+ return {
3011
+ compare: function(actual) {
3012
+ return {
3013
+ pass: !!actual
3014
+ };
3015
+ }
3016
+ };
3017
+ }
3018
+
3019
+ return toBeTruthy;
3020
+ };
3021
+
3022
+ getJasmineRequireObj().toBeUndefined = function() {
3023
+
3024
+ function toBeUndefined() {
3025
+ return {
3026
+ compare: function(actual) {
3027
+ return {
3028
+ pass: void 0 === actual
3029
+ };
3030
+ }
3031
+ };
3032
+ }
3033
+
3034
+ return toBeUndefined;
3035
+ };
3036
+
3037
+ getJasmineRequireObj().toContain = function() {
3038
+ function toContain(util, customEqualityTesters) {
3039
+ customEqualityTesters = customEqualityTesters || [];
3040
+
3041
+ return {
3042
+ compare: function(actual, expected) {
3043
+
3044
+ return {
3045
+ pass: util.contains(actual, expected, customEqualityTesters)
3046
+ };
3047
+ }
3048
+ };
3049
+ }
3050
+
3051
+ return toContain;
3052
+ };
3053
+
3054
+ getJasmineRequireObj().toEqual = function() {
3055
+
3056
+ function toEqual(util, customEqualityTesters) {
3057
+ customEqualityTesters = customEqualityTesters || [];
3058
+
3059
+ return {
3060
+ compare: function(actual, expected) {
3061
+ var result = {
3062
+ pass: false
3063
+ };
3064
+
3065
+ result.pass = util.equals(actual, expected, customEqualityTesters);
3066
+
3067
+ return result;
3068
+ }
3069
+ };
3070
+ }
3071
+
3072
+ return toEqual;
3073
+ };
3074
+
3075
+ getJasmineRequireObj().toHaveBeenCalled = function(j$) {
3076
+
3077
+ function toHaveBeenCalled() {
3078
+ return {
3079
+ compare: function(actual) {
3080
+ var result = {};
3081
+
3082
+ if (!j$.isSpy(actual)) {
3083
+ throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
3084
+ }
3085
+
3086
+ if (arguments.length > 1) {
3087
+ throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
3088
+ }
3089
+
3090
+ result.pass = actual.calls.any();
3091
+
3092
+ result.message = result.pass ?
3093
+ 'Expected spy ' + actual.and.identity() + ' not to have been called.' :
3094
+ 'Expected spy ' + actual.and.identity() + ' to have been called.';
3095
+
3096
+ return result;
3097
+ }
3098
+ };
3099
+ }
3100
+
3101
+ return toHaveBeenCalled;
3102
+ };
3103
+
3104
+ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) {
3105
+
3106
+ function toHaveBeenCalledTimes() {
3107
+ return {
3108
+ compare: function(actual, expected) {
3109
+ if (!j$.isSpy(actual)) {
3110
+ throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
3111
+ }
3112
+
3113
+ var args = Array.prototype.slice.call(arguments, 0),
3114
+ result = { pass: false };
3115
+
3116
+ if(!expected){
3117
+ throw new Error('Expected times failed is required as an argument.');
3118
+ }
3119
+
3120
+ actual = args[0];
3121
+ var calls = actual.calls.count();
3122
+ var timesMessage = expected === 1 ? 'once' : expected + ' times';
3123
+ result.pass = calls === expected;
3124
+ result.message = result.pass ?
3125
+ 'Expected spy ' + actual.and.identity() + ' not to have been called ' + timesMessage + '. It was called ' + calls + ' times.' :
3126
+ 'Expected spy ' + actual.and.identity() + ' to have been called ' + timesMessage + '. It was called ' + calls + ' times.';
3127
+ return result;
3128
+ }
3129
+ };
3130
+ }
3131
+
3132
+ return toHaveBeenCalledTimes;
3133
+ };
3134
+
3135
+ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
3136
+
3137
+ function toHaveBeenCalledWith(util, customEqualityTesters) {
3138
+ return {
3139
+ compare: function() {
3140
+ var args = Array.prototype.slice.call(arguments, 0),
3141
+ actual = args[0],
3142
+ expectedArgs = args.slice(1),
3143
+ result = { pass: false };
3144
+
3145
+ if (!j$.isSpy(actual)) {
3146
+ throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
3147
+ }
3148
+
3149
+ if (!actual.calls.any()) {
3150
+ result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; };
3151
+ return result;
3152
+ }
3153
+
3154
+ if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
3155
+ result.pass = true;
3156
+ result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
3157
+ } else {
3158
+ result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; };
3159
+ }
3160
+
3161
+ return result;
3162
+ }
3163
+ };
3164
+ }
3165
+
3166
+ return toHaveBeenCalledWith;
3167
+ };
3168
+
3169
+ getJasmineRequireObj().toMatch = function(j$) {
3170
+
3171
+ function toMatch() {
3172
+ return {
3173
+ compare: function(actual, expected) {
3174
+ if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
3175
+ throw new Error('Expected is not a String or a RegExp');
3176
+ }
3177
+
3178
+ var regexp = new RegExp(expected);
3179
+
3180
+ return {
3181
+ pass: regexp.test(actual)
3182
+ };
3183
+ }
3184
+ };
3185
+ }
3186
+
3187
+ return toMatch;
3188
+ };
3189
+
3190
+ getJasmineRequireObj().toThrow = function(j$) {
3191
+
3192
+ function toThrow(util) {
3193
+ return {
3194
+ compare: function(actual, expected) {
3195
+ var result = { pass: false },
3196
+ threw = false,
3197
+ thrown;
3198
+
3199
+ if (typeof actual != 'function') {
3200
+ throw new Error('Actual is not a Function');
3201
+ }
3202
+
3203
+ try {
3204
+ actual();
3205
+ } catch (e) {
3206
+ threw = true;
3207
+ thrown = e;
3208
+ }
3209
+
3210
+ if (!threw) {
3211
+ result.message = 'Expected function to throw an exception.';
3212
+ return result;
3213
+ }
3214
+
3215
+ if (arguments.length == 1) {
3216
+ result.pass = true;
3217
+ result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; };
3218
+
3219
+ return result;
3220
+ }
3221
+
3222
+ if (util.equals(thrown, expected)) {
3223
+ result.pass = true;
3224
+ result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; };
3225
+ } else {
3226
+ result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; };
3227
+ }
3228
+
3229
+ return result;
3230
+ }
3231
+ };
3232
+ }
3233
+
3234
+ return toThrow;
3235
+ };
3236
+
3237
+ getJasmineRequireObj().toThrowError = function(j$) {
3238
+ function toThrowError () {
3239
+ return {
3240
+ compare: function(actual) {
3241
+ var threw = false,
3242
+ pass = {pass: true},
3243
+ fail = {pass: false},
3244
+ thrown;
3245
+
3246
+ if (typeof actual != 'function') {
3247
+ throw new Error('Actual is not a Function');
3248
+ }
3249
+
3250
+ var errorMatcher = getMatcher.apply(null, arguments);
3251
+
3252
+ try {
3253
+ actual();
3254
+ } catch (e) {
3255
+ threw = true;
3256
+ thrown = e;
3257
+ }
3258
+
3259
+ if (!threw) {
3260
+ fail.message = 'Expected function to throw an Error.';
3261
+ return fail;
3262
+ }
3263
+
3264
+ if (!(thrown instanceof Error)) {
3265
+ fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; };
3266
+ return fail;
3267
+ }
3268
+
3269
+ if (errorMatcher.hasNoSpecifics()) {
3270
+ pass.message = 'Expected function not to throw an Error, but it threw ' + j$.fnNameFor(thrown) + '.';
3271
+ return pass;
3272
+ }
3273
+
3274
+ if (errorMatcher.matches(thrown)) {
3275
+ pass.message = function() {
3276
+ return 'Expected function not to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() + '.';
3277
+ };
3278
+ return pass;
3279
+ } else {
3280
+ fail.message = function() {
3281
+ return 'Expected function to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() +
3282
+ ', but it threw ' + errorMatcher.thrownDescription(thrown) + '.';
3283
+ };
3284
+ return fail;
3285
+ }
3286
+ }
3287
+ };
3288
+
3289
+ function getMatcher() {
3290
+ var expected = null,
3291
+ errorType = null;
3292
+
3293
+ if (arguments.length == 2) {
3294
+ expected = arguments[1];
3295
+ if (isAnErrorType(expected)) {
3296
+ errorType = expected;
3297
+ expected = null;
3298
+ }
3299
+ } else if (arguments.length > 2) {
3300
+ errorType = arguments[1];
3301
+ expected = arguments[2];
3302
+ if (!isAnErrorType(errorType)) {
3303
+ throw new Error('Expected error type is not an Error.');
3304
+ }
3305
+ }
3306
+
3307
+ if (expected && !isStringOrRegExp(expected)) {
3308
+ if (errorType) {
3309
+ throw new Error('Expected error message is not a string or RegExp.');
3310
+ } else {
3311
+ throw new Error('Expected is not an Error, string, or RegExp.');
3312
+ }
3313
+ }
3314
+
3315
+ function messageMatch(message) {
3316
+ if (typeof expected == 'string') {
3317
+ return expected == message;
3318
+ } else {
3319
+ return expected.test(message);
3320
+ }
3321
+ }
3322
+
3323
+ return {
3324
+ errorTypeDescription: errorType ? j$.fnNameFor(errorType) : 'an exception',
3325
+ thrownDescription: function(thrown) {
3326
+ var thrownName = errorType ? j$.fnNameFor(thrown.constructor) : 'an exception',
3327
+ thrownMessage = '';
3328
+
3329
+ if (expected) {
3330
+ thrownMessage = ' with message ' + j$.pp(thrown.message);
3331
+ }
3332
+
3333
+ return thrownName + thrownMessage;
3334
+ },
3335
+ messageDescription: function() {
3336
+ if (expected === null) {
3337
+ return '';
3338
+ } else if (expected instanceof RegExp) {
3339
+ return ' with a message matching ' + j$.pp(expected);
3340
+ } else {
3341
+ return ' with message ' + j$.pp(expected);
3342
+ }
3343
+ },
3344
+ hasNoSpecifics: function() {
3345
+ return expected === null && errorType === null;
3346
+ },
3347
+ matches: function(error) {
3348
+ return (errorType === null || error instanceof errorType) &&
3349
+ (expected === null || messageMatch(error.message));
3350
+ }
3351
+ };
3352
+ }
3353
+
3354
+ function isStringOrRegExp(potential) {
3355
+ return potential instanceof RegExp || (typeof potential == 'string');
3356
+ }
3357
+
3358
+ function isAnErrorType(type) {
3359
+ if (typeof type !== 'function') {
3360
+ return false;
3361
+ }
3362
+
3363
+ var Surrogate = function() {};
3364
+ Surrogate.prototype = type.prototype;
3365
+ return (new Surrogate()) instanceof Error;
3366
+ }
3367
+ }
3368
+
3369
+ return toThrowError;
3370
+ };
3371
+
3372
+ getJasmineRequireObj().interface = function(jasmine, env) {
3373
+ var jasmineInterface = {
3374
+ describe: function(description, specDefinitions) {
3375
+ return env.describe(description, specDefinitions);
3376
+ },
3377
+
3378
+ xdescribe: function(description, specDefinitions) {
3379
+ return env.xdescribe(description, specDefinitions);
3380
+ },
3381
+
3382
+ fdescribe: function(description, specDefinitions) {
3383
+ return env.fdescribe(description, specDefinitions);
3384
+ },
3385
+
3386
+ it: function() {
3387
+ return env.it.apply(env, arguments);
3388
+ },
3389
+
3390
+ xit: function() {
3391
+ return env.xit.apply(env, arguments);
3392
+ },
3393
+
3394
+ fit: function() {
3395
+ return env.fit.apply(env, arguments);
3396
+ },
3397
+
3398
+ beforeEach: function() {
3399
+ return env.beforeEach.apply(env, arguments);
3400
+ },
3401
+
3402
+ afterEach: function() {
3403
+ return env.afterEach.apply(env, arguments);
3404
+ },
3405
+
3406
+ beforeAll: function() {
3407
+ return env.beforeAll.apply(env, arguments);
3408
+ },
3409
+
3410
+ afterAll: function() {
3411
+ return env.afterAll.apply(env, arguments);
3412
+ },
3413
+
3414
+ expect: function(actual) {
3415
+ return env.expect(actual);
3416
+ },
3417
+
3418
+ pending: function() {
3419
+ return env.pending.apply(env, arguments);
3420
+ },
3421
+
3422
+ fail: function() {
3423
+ return env.fail.apply(env, arguments);
3424
+ },
3425
+
3426
+ spyOn: function(obj, methodName) {
3427
+ return env.spyOn(obj, methodName);
3428
+ },
3429
+
3430
+ jsApiReporter: new jasmine.JsApiReporter({
3431
+ timer: new jasmine.Timer()
3432
+ }),
3433
+
3434
+ jasmine: jasmine
3435
+ };
3436
+
3437
+ jasmine.addCustomEqualityTester = function(tester) {
3438
+ env.addCustomEqualityTester(tester);
3439
+ };
3440
+
3441
+ jasmine.addMatchers = function(matchers) {
3442
+ return env.addMatchers(matchers);
3443
+ };
3444
+
3445
+ jasmine.clock = function() {
3446
+ return env.clock;
3447
+ };
3448
+
3449
+ return jasmineInterface;
3450
+ };
3451
+
3452
+ getJasmineRequireObj().version = function() {
3453
+ return '2.4.1';
3454
+ };