jasmine-core 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/console/console.js +54 -24
  3. data/lib/jasmine-core/__init__.py +1 -0
  4. data/lib/jasmine-core/boot/boot.js +2 -63
  5. data/lib/jasmine-core/boot/node_boot.js +19 -0
  6. data/lib/jasmine-core/boot.js +3 -64
  7. data/lib/jasmine-core/core.py +60 -0
  8. data/lib/jasmine-core/example/node_example/spec/PlayerSpec.js +60 -0
  9. data/lib/jasmine-core/example/node_example/spec/SpecHelper.js +15 -0
  10. data/lib/jasmine-core/example/node_example/src/Player.js +24 -0
  11. data/lib/jasmine-core/example/node_example/src/Song.js +9 -0
  12. data/lib/jasmine-core/jasmine-html.js +119 -74
  13. data/lib/jasmine-core/jasmine.css +61 -54
  14. data/lib/jasmine-core/jasmine.js +961 -456
  15. data/lib/jasmine-core/json2.js +73 -62
  16. data/lib/jasmine-core/node_boot.js +41 -0
  17. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +52 -8
  18. data/lib/jasmine-core/spec/core/AnySpec.js +1 -0
  19. data/lib/jasmine-core/spec/core/ClockSpec.js +122 -18
  20. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +14 -1
  21. data/lib/jasmine-core/spec/core/EnvSpec.js +0 -63
  22. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +7 -0
  23. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +2 -2
  24. data/lib/jasmine-core/spec/core/ExpectationSpec.js +46 -50
  25. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +37 -0
  26. data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
  27. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +6 -0
  28. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +49 -12
  29. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +184 -60
  30. data/lib/jasmine-core/spec/core/SpecSpec.js +46 -108
  31. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +55 -0
  32. data/lib/jasmine-core/spec/core/SpySpec.js +10 -0
  33. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +13 -0
  34. data/lib/jasmine-core/spec/core/SuiteSpec.js +143 -11
  35. data/lib/jasmine-core/spec/core/TimerSpec.js +18 -0
  36. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +34 -32
  37. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +969 -36
  38. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +279 -3
  39. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +18 -1
  40. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +2 -1
  41. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +3 -2
  42. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +2 -1
  43. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +4 -2
  44. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +2 -1
  45. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +17 -3
  46. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +14 -14
  47. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +5 -5
  48. data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +7 -0
  49. data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +33 -0
  50. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +183 -35
  51. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +1 -1
  52. data/lib/jasmine-core/spec/node_suite.js +9 -1
  53. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +104 -0
  54. data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
  55. data/lib/jasmine-core/version.rb +1 -1
  56. data/lib/jasmine-core.js +37 -0
  57. data/lib/jasmine-core.rb +6 -2
  58. metadata +23 -9
  59. data/lib/jasmine-core/spec/support/dev_boot.js +0 -124
@@ -5,7 +5,8 @@ describe("Clock", function() {
5
5
  fakeGlobal = { setTimeout: fakeSetTimeout },
6
6
  delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
7
7
  delayedFn = jasmine.createSpy("delayedFn"),
8
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
8
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
9
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
9
10
 
10
11
  fakeGlobal.setTimeout(delayedFn, 0);
11
12
 
@@ -26,7 +27,8 @@ describe("Clock", function() {
26
27
  fakeGlobal = { clearTimeout: fakeClearTimeout },
27
28
  delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
28
29
  delayedFn = jasmine.createSpy("delayedFn"),
29
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
30
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
31
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
30
32
 
31
33
  fakeGlobal.clearTimeout("foo");
32
34
 
@@ -47,7 +49,8 @@ describe("Clock", function() {
47
49
  fakeGlobal = { setInterval: fakeSetInterval },
48
50
  delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
49
51
  delayedFn = jasmine.createSpy("delayedFn"),
50
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
52
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
53
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
51
54
 
52
55
  fakeGlobal.setInterval(delayedFn, 0);
53
56
 
@@ -68,7 +71,8 @@ describe("Clock", function() {
68
71
  fakeGlobal = { clearInterval: fakeClearInterval },
69
72
  delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
70
73
  delayedFn = jasmine.createSpy("delayedFn"),
71
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
74
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
75
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
72
76
 
73
77
  fakeGlobal.clearInterval("foo");
74
78
 
@@ -97,7 +101,8 @@ describe("Clock", function() {
97
101
  },
98
102
  delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset"]),
99
103
  delayedFn = jasmine.createSpy("delayedFn"),
100
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
104
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
105
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
101
106
 
102
107
  clock.install();
103
108
  clock.uninstall();
@@ -119,7 +124,8 @@ describe("Clock", function() {
119
124
  delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
120
125
  fakeGlobal = { setTimeout: fakeSetTimeout },
121
126
  delayedFn = jasmine.createSpy('delayedFn'),
122
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
127
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
128
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
123
129
 
124
130
  clock.install();
125
131
  clock.setTimeout(delayedFn, 0, 'a', 'b');
@@ -135,7 +141,8 @@ describe("Clock", function() {
135
141
  delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
136
142
  fakeGlobal = { setTimeout: fakeSetTimeout },
137
143
  delayedFn = jasmine.createSpy('delayedFn'),
138
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler),
144
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
145
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate),
139
146
  timeoutId;
140
147
 
141
148
  clock.install();
@@ -149,7 +156,8 @@ describe("Clock", function() {
149
156
  delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['removeFunctionWithId']),
150
157
  fakeGlobal = { setTimeout: fakeClearTimeout },
151
158
  delayedFn = jasmine.createSpy('delayedFn'),
152
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
159
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
160
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
153
161
 
154
162
  clock.install();
155
163
  clock.clearTimeout(123);
@@ -164,7 +172,8 @@ describe("Clock", function() {
164
172
  delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
165
173
  fakeGlobal = { setInterval: fakeSetInterval },
166
174
  delayedFn = jasmine.createSpy('delayedFn'),
167
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
175
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
176
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
168
177
 
169
178
  clock.install();
170
179
  clock.setInterval(delayedFn, 0, 'a', 'b');
@@ -180,7 +189,8 @@ describe("Clock", function() {
180
189
  delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
181
190
  fakeGlobal = { setInterval: fakeSetInterval },
182
191
  delayedFn = jasmine.createSpy('delayedFn'),
183
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler),
192
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
193
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate),
184
194
  intervalId;
185
195
 
186
196
  clock.install();
@@ -194,7 +204,8 @@ describe("Clock", function() {
194
204
  delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['removeFunctionWithId']),
195
205
  fakeGlobal = { setInterval: clearInterval },
196
206
  delayedFn = jasmine.createSpy('delayedFn'),
197
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
207
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
208
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
198
209
 
199
210
  clock.install();
200
211
  clock.clearInterval(123);
@@ -220,7 +231,8 @@ describe("Clock", function() {
220
231
  setTimeout: fakeSetTimeout,
221
232
  setInterval: fakeSetInterval
222
233
  },
223
- clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
234
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
235
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
224
236
 
225
237
  fakeSetTimeout.apply = null;
226
238
  fakeSetInterval.apply = null;
@@ -249,7 +261,8 @@ describe("Clock (acceptance)", function() {
249
261
  delayedFn3 = jasmine.createSpy('delayedFn3'),
250
262
  recurring1 = jasmine.createSpy('recurring1'),
251
263
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
252
- clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler);
264
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
265
+ clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate);
253
266
 
254
267
  clock.install();
255
268
 
@@ -295,7 +308,8 @@ describe("Clock (acceptance)", function() {
295
308
  it("can clear a previously set timeout", function() {
296
309
  var clearedFn = jasmine.createSpy('clearedFn'),
297
310
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
298
- clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler),
311
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
312
+ clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate),
299
313
  timeoutId;
300
314
 
301
315
  clock.install();
@@ -309,10 +323,29 @@ describe("Clock (acceptance)", function() {
309
323
  expect(clearedFn).not.toHaveBeenCalled();
310
324
  });
311
325
 
326
+ it("can clear a previously set interval using that interval's handler", function() {
327
+ var spy = jasmine.createSpy('spy'),
328
+ delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
329
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
330
+ clock = new j$.Clock({setInterval: function() {}}, delayedFunctionScheduler, mockDate),
331
+ intervalId;
332
+
333
+ clock.install();
334
+
335
+ intervalId = clock.setInterval(function() {
336
+ spy();
337
+ clock.clearInterval(intervalId);
338
+ }, 100);
339
+ clock.tick(200);
340
+
341
+ expect(spy.calls.count()).toEqual(1);
342
+ });
343
+
312
344
  it("correctly schedules functions after the Clock has advanced", function() {
313
345
  var delayedFn1 = jasmine.createSpy('delayedFn1'),
314
346
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
315
- clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler);
347
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
348
+ clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate);
316
349
 
317
350
  clock.install();
318
351
 
@@ -328,7 +361,8 @@ describe("Clock (acceptance)", function() {
328
361
  var delayedFn1 = jasmine.createSpy('delayedFn1'),
329
362
  delayedFn2 = jasmine.createSpy('delayedFn2'),
330
363
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
331
- clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler);
364
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
365
+ clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate);
332
366
 
333
367
  delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 0); });
334
368
  clock.install();
@@ -346,7 +380,8 @@ describe("Clock (acceptance)", function() {
346
380
  var delayedFn1 = jasmine.createSpy('delayedFn1'),
347
381
  delayedFn2 = jasmine.createSpy('delayedFn2'),
348
382
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
349
- clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler);
383
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
384
+ clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate);
350
385
 
351
386
  delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 1); });
352
387
  clock.install();
@@ -354,6 +389,75 @@ describe("Clock (acceptance)", function() {
354
389
 
355
390
  clock.tick(6);
356
391
  expect(delayedFn1).toHaveBeenCalled();
357
- expect(delayedFn2).toHaveBeenCalled();
392
+ expect(delayedFn2).toHaveBeenCalled();
393
+ });
394
+
395
+ it("does not mock the Date object by default", function() {
396
+ var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
397
+ global = {Date: Date},
398
+ mockDate = new j$.MockDate(global),
399
+ clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate);
400
+
401
+ clock.install();
402
+
403
+ expect(global.Date).toEqual(Date);
404
+
405
+ var now = new global.Date().getTime();
406
+
407
+ clock.tick(50);
408
+
409
+ expect(new global.Date().getTime() - now).not.toEqual(50);
410
+ });
411
+
412
+ it("mocks the Date object and sets it to current time", function() {
413
+ var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
414
+ global = {Date: Date},
415
+ mockDate = new j$.MockDate(global),
416
+ clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate);
417
+
418
+ clock.install().mockDate();
419
+
420
+ var now = new global.Date().getTime();
421
+
422
+ clock.tick(50);
423
+
424
+ expect(new global.Date().getTime() - now).toEqual(50);
425
+
426
+ var timeoutDate = 0;
427
+ clock.setTimeout(function() {
428
+ timeoutDate = new global.Date().getTime();
429
+ }, 100);
430
+
431
+ clock.tick(100);
432
+
433
+ expect(timeoutDate - now).toEqual(150);
434
+ });
435
+
436
+ it("mocks the Date object and sets it to a given time", function() {
437
+ var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
438
+ global = {Date: Date},
439
+ mockDate = new j$.MockDate(global),
440
+ clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate),
441
+ baseTime = new Date(2013, 9, 23);
442
+
443
+
444
+ clock.install().mockDate(baseTime);
445
+
446
+ var now = new global.Date().getTime();
447
+
448
+ expect(now).toEqual(baseTime.getTime());
449
+
450
+ clock.tick(50);
451
+
452
+ expect(new global.Date().getTime()).toEqual(baseTime.getTime() + 50);
453
+
454
+ var timeoutDate = 0;
455
+ clock.setTimeout(function() {
456
+ timeoutDate = new global.Date().getTime();
457
+ }, 100);
458
+
459
+ clock.tick(100);
460
+
461
+ expect(timeoutDate).toEqual(baseTime.getTime() + 150);
358
462
  });
359
463
  });
@@ -14,7 +14,7 @@ describe("DelayedFunctionScheduler", function() {
14
14
 
15
15
  it("schedules a string for later execution", function() {
16
16
  var scheduler = new j$.DelayedFunctionScheduler(),
17
- strfn = "horrible = true;";
17
+ strfn = "horrible = true;";
18
18
 
19
19
  scheduler.scheduleFunction(strfn, 0);
20
20
 
@@ -242,5 +242,18 @@ describe("DelayedFunctionScheduler", function() {
242
242
  expect(innerFn).toHaveBeenCalled();
243
243
  });
244
244
 
245
+ it("executes recurring functions after rescheduling them", function () {
246
+ var scheduler = new j$.DelayedFunctionScheduler(),
247
+ recurring = function() {
248
+ expect(scheduler.scheduleFunction).toHaveBeenCalled();
249
+ };
250
+
251
+ scheduler.scheduleFunction(recurring, 10, [], true);
252
+
253
+ spyOn(scheduler, "scheduleFunction");
254
+
255
+ scheduler.tick(10);
256
+ });
257
+
245
258
  });
246
259
 
@@ -5,68 +5,6 @@ describe("Env", function() {
5
5
  env = new j$.Env();
6
6
  });
7
7
 
8
- it('removes all spies when env is executed', function(done) {
9
- originalFoo = function() {},
10
- testObj = {
11
- foo: originalFoo
12
- },
13
- firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
14
- env.spyOn(testObj, 'foo');
15
- }),
16
- secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
17
- expect(testObj.foo).toBe(originalFoo);
18
- });
19
- env.describe('test suite', function() {
20
- env.it('spec 0', firstSpec);
21
- env.it('spec 1', secondSpec);
22
- });
23
-
24
- var assertions = function() {
25
- expect(firstSpec).toHaveBeenCalled();
26
- expect(secondSpec).toHaveBeenCalled();
27
- done();
28
- };
29
-
30
- env.addReporter({ jasmineDone: assertions });
31
-
32
- env.execute();
33
- });
34
-
35
- describe("#spyOn", function() {
36
- it("checks for the existence of the object", function() {
37
- expect(function() {
38
- env.spyOn(void 0, 'pants');
39
- }).toThrowError(/could not find an object/);
40
- });
41
-
42
- it("checks for the existence of the method", function() {
43
- var subject = {};
44
-
45
- expect(function() {
46
- env.spyOn(subject, 'pants');
47
- }).toThrowError(/method does not exist/);
48
- });
49
-
50
- it("checks if it has already been spied upon", function() {
51
- var subject = { spiedFunc: function() {} };
52
-
53
- env.spyOn(subject, 'spiedFunc');
54
-
55
- expect(function() {
56
- env.spyOn(subject, 'spiedFunc');
57
- }).toThrowError(/has already been spied upon/);
58
- });
59
-
60
- it("overrides the method on the object and returns the spy", function() {
61
- var originalFunctionWasCalled = false;
62
- var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
63
-
64
- var spy = env.spyOn(subject, 'spiedFunc');
65
-
66
- expect(subject.spiedFunc).toEqual(spy);
67
- });
68
- });
69
-
70
8
  describe("#pending", function() {
71
9
  it("throws the Pending Spec exception", function() {
72
10
  expect(function() {
@@ -82,4 +20,3 @@ describe("Env", function() {
82
20
  });
83
21
  });
84
22
  });
85
-
@@ -35,7 +35,14 @@ describe("ExceptionFormatter", function() {
35
35
  message = exceptionFormatter.message(sampleV8);
36
36
 
37
37
  expect(message).toEqual('A Classic Mistake: you got your foo in my bar');
38
+ });
39
+
40
+ it("formats thrown exceptions that aren't errors", function() {
41
+ var thrown = "crazy error",
42
+ exceptionFormatter = new j$.ExceptionFormatter(),
43
+ message = exceptionFormatter.message(thrown);
38
44
 
45
+ expect(message).toEqual("crazy error thrown");
39
46
  });
40
47
  });
41
48
 
@@ -35,7 +35,7 @@ describe('Exceptions:', function() {
35
35
  env.it('should be a passing test that runs after exceptions are thrown from a async test', secondTest);
36
36
  });
37
37
 
38
- expectations = function() {
38
+ var expectations = function() {
39
39
  expect(secondTest).toHaveBeenCalled();
40
40
  done();
41
41
  };
@@ -55,7 +55,7 @@ describe('Exceptions:', function() {
55
55
  });
56
56
  env.describe("a suite that doesn't throw an exception", secondDescribe);
57
57
 
58
- expectations = function() {
58
+ var expectations = function() {
59
59
  expect(secondDescribe).toHaveBeenCalled();
60
60
  done();
61
61
  };
@@ -1,14 +1,14 @@
1
1
  describe("Expectation", function() {
2
- it(".addMatchers makes matchers available to any expectation", function() {
2
+ it("makes custom matchers available to this expectation", function() {
3
3
  var matchers = {
4
4
  toFoo: function() {},
5
5
  toBar: function() {}
6
6
  },
7
7
  expectation;
8
8
 
9
- j$.Expectation.addMatchers(matchers);
10
-
11
- expectation = new j$.Expectation({});
9
+ expectation = new j$.Expectation({
10
+ customMatchers: matchers
11
+ });
12
12
 
13
13
  expect(expectation.toFoo).toBeDefined();
14
14
  expect(expectation.toBar).toBeDefined();
@@ -27,25 +27,6 @@ describe("Expectation", function() {
27
27
  expect(expectation.toQuux).toBeDefined();
28
28
  });
29
29
 
30
- it(".resetMatchers should keep only core matchers", function() {
31
- var matchers = {
32
- toFoo: function() {}
33
- },
34
- coreMatchers = {
35
- toQuux: function() {}
36
- },
37
- expectation;
38
-
39
- j$.Expectation.addCoreMatchers(coreMatchers);
40
- j$.Expectation.addMatchers(matchers);
41
- j$.Expectation.resetMatchers();
42
-
43
- expectation = new j$.Expectation({});
44
-
45
- expect(expectation.toQuux).toBeDefined();
46
- expect(expectation.toFoo).toBeUndefined();
47
- });
48
-
49
30
  it("Factory builds an expectation/negative expectation", function() {
50
31
  var builtExpectation = j$.Expectation.Factory();
51
32
 
@@ -65,10 +46,9 @@ describe("Expectation", function() {
65
46
  addExpectationResult = jasmine.createSpy("addExpectationResult"),
66
47
  expectation;
67
48
 
68
- j$.Expectation.addMatchers(matchers);
69
-
70
49
  expectation = new j$.Expectation({
71
50
  util: util,
51
+ customMatchers: matchers,
72
52
  customEqualityTesters: customEqualityTesters,
73
53
  actual: "an actual",
74
54
  addExpectationResult: addExpectationResult
@@ -94,10 +74,9 @@ describe("Expectation", function() {
94
74
  addExpectationResult = jasmine.createSpy("addExpectationResult"),
95
75
  expectation;
96
76
 
97
- j$.Expectation.addMatchers(matchers);
98
-
99
77
  expectation = new j$.Expectation({
100
78
  util: util,
79
+ customMatchers: matchers,
101
80
  actual: "an actual",
102
81
  addExpectationResult: addExpectationResult
103
82
  });
@@ -121,10 +100,8 @@ describe("Expectation", function() {
121
100
  addExpectationResult = jasmine.createSpy("addExpectationResult"),
122
101
  expectation;
123
102
 
124
- j$.Expectation.addMatchers(matchers);
125
-
126
103
  expectation = new j$.Expectation({
127
- matchers: matchers,
104
+ customMatchers: matchers,
128
105
  util: util,
129
106
  actual: "an actual",
130
107
  addExpectationResult: addExpectationResult
@@ -155,10 +132,8 @@ describe("Expectation", function() {
155
132
  addExpectationResult = jasmine.createSpy("addExpectationResult"),
156
133
  expectation;
157
134
 
158
- j$.Expectation.addMatchers(matchers);
159
-
160
135
  expectation = new j$.Expectation({
161
- matchers: matchers,
136
+ customMatchers: matchers,
162
137
  util: util,
163
138
  actual: "an actual",
164
139
  addExpectationResult: addExpectationResult
@@ -191,10 +166,41 @@ describe("Expectation", function() {
191
166
  addExpectationResult = jasmine.createSpy("addExpectationResult"),
192
167
  expectation;
193
168
 
194
- j$.Expectation.addMatchers(matchers);
169
+ expectation = new j$.Expectation({
170
+ actual: "an actual",
171
+ customMatchers: matchers,
172
+ addExpectationResult: addExpectationResult
173
+ });
174
+
175
+ expectation.toFoo("hello");
176
+
177
+ expect(addExpectationResult).toHaveBeenCalledWith(false, {
178
+ matcherName: "toFoo",
179
+ passed: false,
180
+ expected: "hello",
181
+ actual: "an actual",
182
+ message: "I am a custom message"
183
+ });
184
+ });
185
+
186
+ it("reports a failing result with a custom fail message function to the spec when the comparison fails", function() {
187
+ var matchers = {
188
+ toFoo: function() {
189
+ return {
190
+ compare: function() {
191
+ return {
192
+ pass: false,
193
+ message: function() { return "I am a custom message"; }
194
+ };
195
+ }
196
+ };
197
+ }
198
+ },
199
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
200
+ expectation;
195
201
 
196
202
  expectation = new j$.Expectation({
197
- matchers: matchers,
203
+ customMatchers: matchers,
198
204
  actual: "an actual",
199
205
  addExpectationResult: addExpectationResult
200
206
  });
@@ -225,10 +231,8 @@ describe("Expectation", function() {
225
231
  actual = "an actual",
226
232
  expectation;
227
233
 
228
- j$.Expectation.addMatchers(matchers);
229
-
230
234
  expectation = new j$.Expectation({
231
- matchers: matchers,
235
+ customMatchers: matchers,
232
236
  actual: "an actual",
233
237
  addExpectationResult: addExpectationResult,
234
238
  isNot: true
@@ -260,10 +264,8 @@ describe("Expectation", function() {
260
264
  actual = "an actual",
261
265
  expectation;
262
266
 
263
- j$.Expectation.addMatchers(matchers);
264
-
265
267
  expectation = new j$.Expectation({
266
- matchers: matchers,
268
+ customMatchers: matchers,
267
269
  actual: "an actual",
268
270
  util: util,
269
271
  addExpectationResult: addExpectationResult,
@@ -298,10 +300,8 @@ describe("Expectation", function() {
298
300
  actual = "an actual",
299
301
  expectation;
300
302
 
301
- j$.Expectation.addMatchers(matchers);
302
-
303
303
  expectation = new j$.Expectation({
304
- matchers: matchers,
304
+ customMatchers: matchers,
305
305
  actual: "an actual",
306
306
  addExpectationResult: addExpectationResult,
307
307
  isNot: true
@@ -331,10 +331,8 @@ describe("Expectation", function() {
331
331
  actual = "an actual",
332
332
  expectation;
333
333
 
334
- j$.Expectation.addMatchers(matchers);
335
-
336
334
  expectation = new j$.Expectation({
337
- matchers: matchers,
335
+ customMatchers: matchers,
338
336
  actual: "an actual",
339
337
  addExpectationResult: addExpectationResult,
340
338
  isNot: true
@@ -369,10 +367,8 @@ describe("Expectation", function() {
369
367
  actual = "an actual",
370
368
  expectation;
371
369
 
372
- j$.Expectation.addMatchers(matchers);
373
-
374
370
  expectation = new j$.Expectation({
375
- matchers: matchers,
371
+ customMatchers: matchers,
376
372
  actual: "an actual",
377
373
  addExpectationResult: addExpectationResult,
378
374
  isNot: true
@@ -178,6 +178,43 @@ describe("JsApiReporter", function() {
178
178
  });
179
179
  });
180
180
 
181
+ describe("#suiteResults", function(){
182
+ var reporter, suiteResult1, suiteResult2;
183
+ beforeEach(function() {
184
+ reporter = new j$.JsApiReporter({});
185
+ suiteStarted1 = {
186
+ id: 1
187
+ };
188
+ suiteResult1 = {
189
+ id: 1,
190
+ status: 'failed',
191
+ failedExpectations: [{ message: 'My After All Exception' }]
192
+ };
193
+ suiteResult2 = {
194
+ id: 2,
195
+ status: 'finished'
196
+ };
197
+
198
+ reporter.suiteStarted(suiteStarted1);
199
+ reporter.suiteDone(suiteResult1);
200
+ reporter.suiteDone(suiteResult2);
201
+ });
202
+
203
+ it('should not include suite starts', function(){
204
+ expect(reporter.suiteResults(0,3).length).toEqual(2);
205
+ });
206
+
207
+ it("should return a slice of results", function() {
208
+ expect(reporter.suiteResults(0, 1)).toEqual([suiteResult1]);
209
+ expect(reporter.suiteResults(1, 1)).toEqual([suiteResult2]);
210
+ });
211
+
212
+ it("returns nothing for out of bounds indicies", function() {
213
+ expect(reporter.suiteResults(0, 3)).toEqual([suiteResult1, suiteResult2]);
214
+ expect(reporter.suiteResults(2, 3)).toEqual([]);
215
+ });
216
+ });
217
+
181
218
  describe("#executionTime", function() {
182
219
  it("should start the timer when jasmine starts", function() {
183
220
  var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),