therubyracer 0.7.0 → 0.7.1.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of therubyracer might be problematic. Click here for more details.

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