jasnode 0.2.0.0

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