jasmine-core 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/console/console.js +26 -2
  3. data/lib/jasmine-core.js +31 -23
  4. data/lib/jasmine-core/boot.js +1 -1
  5. data/lib/jasmine-core/boot/boot.js +1 -1
  6. data/lib/jasmine-core/example/node_example/spec/PlayerSpec.js +2 -2
  7. data/lib/jasmine-core/jasmine-html.js +16 -2
  8. data/lib/jasmine-core/jasmine.css +11 -10
  9. data/lib/jasmine-core/jasmine.js +709 -395
  10. data/lib/jasmine-core/json2.js +73 -62
  11. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +39 -8
  12. data/lib/jasmine-core/spec/core/ClockSpec.js +19 -1
  13. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +13 -0
  14. data/lib/jasmine-core/spec/core/EnvSpec.js +0 -63
  15. data/lib/jasmine-core/spec/core/ExpectationSpec.js +15 -53
  16. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +37 -0
  17. data/lib/jasmine-core/spec/core/MockDateSpec.js +1 -0
  18. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +8 -2
  19. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +91 -66
  20. data/lib/jasmine-core/spec/core/SpecSpec.js +25 -26
  21. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +55 -0
  22. data/lib/jasmine-core/spec/core/SpySpec.js +10 -0
  23. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +13 -0
  24. data/lib/jasmine-core/spec/core/SuiteSpec.js +108 -10
  25. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +34 -32
  26. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +950 -35
  27. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +279 -3
  28. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +10 -1
  29. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +5 -5
  30. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +30 -2
  31. data/lib/jasmine-core/spec/node_suite.js +195 -0
  32. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +104 -0
  33. data/lib/jasmine-core/version.rb +1 -1
  34. metadata +6 -3
@@ -1,4 +1,44 @@
1
1
  describe("Env integration", function() {
2
+ beforeEach(function() {
3
+ jasmine.addMatchers({
4
+ toHaveFailedExpecationsForRunnable: function(util, customeEqualityTesters) {
5
+ return {
6
+ compare: function(actual, fullName, expectedFailures) {
7
+ var foundRunnable = false, expectations = true, foundFailures = [];
8
+ for (var i = 0; i < actual.calls.count(); i++) {
9
+ var args = actual.calls.argsFor(i)[0];
10
+
11
+ if (args.fullName === fullName) {
12
+ foundRunnable = true;
13
+
14
+ for (var j = 0; j < args.failedExpectations.length; j++) {
15
+ foundFailures.push(args.failedExpectations[j].message);
16
+ }
17
+
18
+ for (var j = 0; j < expectedFailures.length; j++) {
19
+ var failure = foundFailures[j];
20
+ var expectedFailure = expectedFailures[j];
21
+
22
+ if (Object.prototype.toString.call(expectedFailure) === '[object RegExp]') {
23
+ expectations = expectations && expectedFailure.test(failure);
24
+ } else {
25
+ expectations = expectations && failure === expectedFailure;
26
+ }
27
+ }
28
+ break;
29
+ }
30
+ }
31
+
32
+ return {
33
+ pass: foundRunnable && expectations,
34
+ message: !foundRunnable ? 'The runnable "' + fullName + '" never finished' :
35
+ 'Expected runnable "' + fullName + '" to have failures ' + jasmine.pp(expectedFailures) + ' but it had ' + jasmine.pp(foundFailures)
36
+ };
37
+ }
38
+ };
39
+ }
40
+ });
41
+ });
2
42
 
3
43
  it("Suites execute as expected (no nesting)", function(done) {
4
44
  var env = new j$.Env(),
@@ -80,7 +120,7 @@ describe("Env integration", function() {
80
120
 
81
121
  env.describe("Outer suite", function() {
82
122
  env.it("an outer spec", function() {
83
- calls.push('an outer spec')
123
+ calls.push('an outer spec');
84
124
  });
85
125
  env.describe("Inner suite", function() {
86
126
  env.it("an inner spec", function() {
@@ -101,6 +141,53 @@ describe("Env integration", function() {
101
141
  env.execute();
102
142
  });
103
143
 
144
+ it('explicitly fails a spec', function(done) {
145
+ var env = new j$.Env(),
146
+ specDone = jasmine.createSpy('specDone');
147
+
148
+ env.addReporter({
149
+ specDone: specDone,
150
+ jasmineDone: function() {
151
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
152
+ description: 'has a default message',
153
+ failedExpectations: [jasmine.objectContaining({
154
+ message: 'Failed'
155
+ })]
156
+ }));
157
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
158
+ description: 'specifies a message',
159
+ failedExpectations: [jasmine.objectContaining({
160
+ message: 'Failed: messy message'
161
+ })]
162
+ }));
163
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
164
+ description: 'has a message from an Error',
165
+ failedExpectations: [jasmine.objectContaining({
166
+ message: 'Failed: error message'
167
+ })]
168
+ }));
169
+ done();
170
+ }
171
+ });
172
+
173
+ env.describe('failing', function() {
174
+ env.it('has a default message', function() {
175
+ env.fail();
176
+ });
177
+
178
+ env.it('specifies a message', function() {
179
+ env.fail('messy message');
180
+ });
181
+
182
+ env.it('has a message from an Error', function() {
183
+ env.fail(new Error('error message'));
184
+ });
185
+ });
186
+
187
+ env.execute();
188
+ });
189
+
190
+
104
191
  it("calls associated befores/specs/afters with the same 'this'", function(done) {
105
192
  var env = new j$.Env();
106
193
 
@@ -165,6 +252,305 @@ describe("Env integration", function() {
165
252
  env.execute();
166
253
  });
167
254
 
255
+ it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
256
+ var env = new j$.Env(),
257
+ before = jasmine.createSpy('beforeAll'),
258
+ after = jasmine.createSpy('afterAll');
259
+
260
+ env.addReporter({
261
+ jasmineDone: function() {
262
+ expect(after).toHaveBeenCalled();
263
+ expect(after.calls.count()).toBe(1);
264
+ expect(before.calls.count()).toBe(1);
265
+ done();
266
+ }
267
+ });
268
+
269
+ env.describe("with beforeAll and afterAll", function() {
270
+ env.it("spec", function() {
271
+ expect(before).toHaveBeenCalled();
272
+ expect(after).not.toHaveBeenCalled();
273
+ });
274
+
275
+ env.it("another spec", function() {
276
+ expect(before).toHaveBeenCalled();
277
+ expect(after).not.toHaveBeenCalled();
278
+ });
279
+
280
+ env.beforeAll(before);
281
+ env.afterAll(after);
282
+ });
283
+
284
+ env.execute();
285
+ });
286
+
287
+ it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
288
+ var env = new j$.Env(),
289
+ before = jasmine.createSpy('beforeAll'),
290
+ after = jasmine.createSpy('afterAll');
291
+
292
+ env.addReporter({
293
+ jasmineDone: function() {
294
+ expect(after).toHaveBeenCalled();
295
+ expect(after.calls.count()).toBe(1);
296
+ expect(before.calls.count()).toBe(1);
297
+ done();
298
+ }
299
+ });
300
+
301
+ env.describe("with beforeAll and afterAll", function() {
302
+ env.it("spec", function() {
303
+ expect(before).toHaveBeenCalled();
304
+ expect(after).not.toHaveBeenCalled();
305
+ });
306
+
307
+ env.it("another spec", function() {
308
+ expect(before).toHaveBeenCalled();
309
+ expect(after).not.toHaveBeenCalled();
310
+ });
311
+
312
+ env.beforeAll(function(beforeCallbackUnderTest) {
313
+ before();
314
+ beforeCallbackUnderTest();
315
+ });
316
+
317
+ env.afterAll(function(afterCallbackUnderTest) {
318
+ after();
319
+ afterCallbackUnderTest();
320
+ });
321
+ });
322
+
323
+ env.execute();
324
+ });
325
+
326
+ it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
327
+ var env = new j$.Env();
328
+
329
+ env.addReporter({jasmineDone: done});
330
+
331
+ env.describe("with beforeAll and afterAll", function() {
332
+ env.beforeAll(function() {
333
+ this.x = 1;
334
+ });
335
+
336
+ env.it("has an x at the root", function() {
337
+ expect(this.x).toBe(1);
338
+ });
339
+
340
+ env.describe("child that deletes", function() {
341
+ env.beforeAll(function() {
342
+ expect(this.x).toBe(1);
343
+ delete this.x;
344
+ });
345
+
346
+ env.it("has no x", function() {
347
+ expect(this.x).not.toBeDefined();
348
+ });
349
+ });
350
+
351
+ env.describe("child should still have x", function() {
352
+ env.beforeAll(function(innerDone) {
353
+ expect(this.x).toBe(1);
354
+ innerDone();
355
+ });
356
+
357
+ env.it("has an x", function() {
358
+ expect(this.x).toBe(1);
359
+ delete this.x;
360
+ });
361
+
362
+ env.it("still has an x", function() {
363
+ expect(this.x).toBe(1);
364
+ });
365
+
366
+ env.it("adds a y", function() {
367
+ this.y = 2;
368
+ expect(this.y).toBe(2);
369
+ });
370
+
371
+ env.it("doesn't have y that was added in sibling", function() {
372
+ expect(this.y).not.toBeDefined();
373
+ });
374
+ });
375
+ });
376
+
377
+ env.execute();
378
+ });
379
+
380
+ it("fails all underlying specs when the beforeAll fails", function (done) {
381
+ var env = new j$.Env(),
382
+ reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
383
+
384
+ reporter.jasmineDone.and.callFake(function() {
385
+ expect(reporter.specDone.calls.count()).toEqual(2);
386
+
387
+ expect(reporter.specDone.calls.argsFor(0)[0])
388
+ .toEqual(jasmine.objectContaining({status: 'failed'}));
389
+ expect(reporter.specDone.calls.argsFor(0)[0].failedExpectations[0].message)
390
+ .toEqual("Expected 1 to be 2.");
391
+
392
+ expect(reporter.specDone.calls.argsFor(1)[0])
393
+ .toEqual(jasmine.objectContaining({status: 'failed'}));
394
+ expect(reporter.specDone.calls.argsFor(1)[0].failedExpectations[0].message)
395
+ .toEqual("Expected 1 to be 2.");
396
+ done();
397
+ });
398
+
399
+ env.addReporter(reporter);
400
+
401
+ env.describe('A suite', function(){
402
+ env.beforeAll(function() {
403
+ env.expect(1).toBe(2);
404
+ });
405
+
406
+ env.it("spec that will be failed", function() {
407
+ });
408
+
409
+ env.describe("nesting", function() {
410
+ env.it("another spec to fail", function() {
411
+ });
412
+ });
413
+ });
414
+
415
+ env.execute();
416
+ });
417
+
418
+ describe('suiteDone reporting', function(){
419
+ it("reports when an afterAll fails an expectation", function(done) {
420
+ var env = new j$.Env(),
421
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
422
+
423
+ reporter.jasmineDone.and.callFake(function() {
424
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
425
+ 'Expected 1 to equal 2.',
426
+ 'Expected 2 to equal 3.'
427
+ ]);
428
+ done();
429
+ });
430
+
431
+ env.addReporter(reporter);
432
+
433
+ env.describe('my suite', function() {
434
+ env.it('my spec', function() {
435
+ });
436
+
437
+ env.afterAll(function() {
438
+ env.expect(1).toEqual(2);
439
+ env.expect(2).toEqual(3);
440
+ });
441
+ });
442
+
443
+ env.execute();
444
+ });
445
+
446
+ it("if there are no specs, it still reports correctly", function(done) {
447
+ var env = new j$.Env(),
448
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
449
+
450
+ reporter.jasmineDone.and.callFake(function() {
451
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('outer suite', [
452
+ 'Expected 1 to equal 2.',
453
+ 'Expected 2 to equal 3.'
454
+ ]);
455
+ done();
456
+ });
457
+
458
+ env.addReporter(reporter);
459
+
460
+ env.describe('outer suite', function() {
461
+ env.describe('inner suite', function() {
462
+ env.it('spec', function(){ });
463
+ });
464
+
465
+ env.afterAll(function() {
466
+ env.expect(1).toEqual(2);
467
+ env.expect(2).toEqual(3);
468
+ });
469
+ });
470
+
471
+ env.execute();
472
+ });
473
+
474
+ it("reports when afterAll throws an exception", function(done) {
475
+ var env = new j$.Env(),
476
+ error = new Error('After All Exception'),
477
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
478
+
479
+ reporter.jasmineDone.and.callFake(function() {
480
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
481
+ (/^Error: After All Exception/)
482
+ ]);
483
+ done();
484
+ });
485
+
486
+ env.addReporter(reporter);
487
+
488
+ env.describe('my suite', function() {
489
+ env.it('my spec', function() {
490
+ });
491
+
492
+ env.afterAll(function() {
493
+ throw error;
494
+ });
495
+ });
496
+
497
+ env.execute();
498
+ });
499
+
500
+ it("reports when an async afterAll fails an expectation", function(done) {
501
+ var env = new j$.Env(),
502
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
503
+
504
+ reporter.jasmineDone.and.callFake(function() {
505
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
506
+ 'Expected 1 to equal 2.'
507
+ ]);
508
+ done();
509
+ });
510
+
511
+ env.addReporter(reporter);
512
+
513
+ env.describe('my suite', function() {
514
+ env.it('my spec', function() {
515
+ });
516
+
517
+ env.afterAll(function(afterAllDone) {
518
+ env.expect(1).toEqual(2);
519
+ afterAllDone();
520
+ });
521
+ });
522
+
523
+ env.execute();
524
+ });
525
+
526
+ it("reports when an async afterAll throws an exception", function(done) {
527
+ var env = new j$.Env(),
528
+ error = new Error('After All Exception'),
529
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
530
+
531
+
532
+ reporter.jasmineDone.and.callFake(function() {
533
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
534
+ (/^Error: After All Exception/)
535
+ ]);
536
+ done();
537
+ });
538
+
539
+ env.addReporter(reporter);
540
+
541
+ env.describe('my suite', function() {
542
+ env.it('my spec', function() {
543
+ });
544
+
545
+ env.afterAll(function(afterAllDone) {
546
+ throw error;
547
+ });
548
+ });
549
+
550
+ env.execute();
551
+ });
552
+ });
553
+
168
554
  it("Allows specifying which specs and suites to run", function(done) {
169
555
  var env = new j$.Env(),
170
556
  calls = [],
@@ -201,16 +587,61 @@ describe("Env integration", function() {
201
587
  env.execute([secondSuite.id, firstSpec.id]);
202
588
  });
203
589
 
204
- it("Functions can be spied on and have their calls tracked", function () {
205
- var env = new j$.Env();
590
+ it('runs before and after all functions for runnables provided to .execute()', function(done) {
591
+ var env = new j$.Env(),
592
+ calls = [],
593
+ first_spec,
594
+ second_spec;
206
595
 
207
- var originalFunctionWasCalled = false;
208
- var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
596
+ var assertions = function() {
597
+ expect(calls).toEqual([
598
+ "before",
599
+ "first spec",
600
+ "after",
601
+ "before",
602
+ "second spec",
603
+ "after"
604
+ ]);
605
+ done();
606
+ };
209
607
 
210
- var spy = env.spyOn(subject, 'spiedFunc');
608
+ env.addReporter({jasmineDone: assertions});
211
609
 
212
- expect(subject.spiedFunc).toEqual(spy);
610
+ env.describe("first suite", function() {
611
+ env.beforeAll(function() {
612
+ calls.push("before");
613
+ });
614
+ env.afterAll(function() {
615
+ calls.push("after")
616
+ });
617
+ first_spec = env.it("spec", function() {
618
+ calls.push('first spec');
619
+ });
620
+ second_spec = env.it("spec 2", function() {
621
+ calls.push("second spec");
622
+ });
623
+ });
624
+
625
+ env.execute([first_spec.id, second_spec.id]);
626
+ });
627
+
628
+ it("Functions can be spied on and have their calls tracked", function (done) {
629
+ var env = new j$.Env();
630
+
631
+ var originalFunctionWasCalled = false;
632
+ var subject = {
633
+ spiedFunc: function() {
634
+ originalFunctionWasCalled = true;
635
+ return "original result";
636
+ }
637
+ };
638
+
639
+ env.addReporter({jasmineDone: done});
640
+
641
+ env.it("works with spies", function() {
642
+ var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result");
213
643
 
644
+ expect(subject.spiedFunc).toEqual(spy);
214
645
  expect(subject.spiedFunc.calls.any()).toEqual(false);
215
646
  expect(subject.spiedFunc.calls.count()).toEqual(0);
216
647
 
@@ -220,11 +651,76 @@ describe("Env integration", function() {
220
651
  expect(subject.spiedFunc.calls.count()).toEqual(1);
221
652
  expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
222
653
  expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
654
+ expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("stubbed result");
223
655
  expect(originalFunctionWasCalled).toEqual(false);
224
656
 
657
+ subject.spiedFunc.and.callThrough();
225
658
  subject.spiedFunc('bar');
226
659
  expect(subject.spiedFunc.calls.count()).toEqual(2);
227
660
  expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
661
+ expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("original result");
662
+ expect(originalFunctionWasCalled).toEqual(true);
663
+ });
664
+
665
+ env.execute();
666
+ });
667
+
668
+ it('removes all spies added in a spec after the spec is complete', function(done) {
669
+ var env = new j$.Env(),
670
+ originalFoo = function() {},
671
+ testObj = {
672
+ foo: originalFoo
673
+ },
674
+ firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
675
+ env.spyOn(testObj, 'foo');
676
+ }),
677
+ secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
678
+ expect(testObj.foo).toBe(originalFoo);
679
+ });
680
+ env.describe('test suite', function() {
681
+ env.it('spec 0', firstSpec);
682
+ env.it('spec 1', secondSpec);
683
+ });
684
+
685
+ var assertions = function() {
686
+ expect(firstSpec).toHaveBeenCalled();
687
+ expect(secondSpec).toHaveBeenCalled();
688
+ done();
689
+ };
690
+
691
+ env.addReporter({ jasmineDone: assertions });
692
+
693
+ env.execute();
694
+ });
695
+
696
+ it('removes all spies added in a suite after the suite is complete', function(done) {
697
+ var env = new j$.Env(),
698
+ originalFoo = function() {},
699
+ testObj = {
700
+ foo: originalFoo
701
+ };
702
+
703
+ env.describe('test suite', function() {
704
+ env.beforeAll(function() { env.spyOn(testObj, 'foo');})
705
+
706
+ env.it('spec 0', function() {
707
+ expect(j$.isSpy(testObj.foo)).toBe(true);
708
+ });
709
+
710
+ env.it('spec 1', function() {
711
+ expect(j$.isSpy(testObj.foo)).toBe(true);
712
+ });
713
+ });
714
+
715
+ env.describe('another suite', function() {
716
+ env.it('spec 2', function() {
717
+ expect(j$.isSpy(testObj.foo)).toBe(false);
718
+ });
719
+ });
720
+
721
+ env.addReporter({ jasmineDone: done });
722
+
723
+ env.execute();
228
724
  });
229
725
 
230
726
  it("Mock clock can be installed and used in tests", function(done) {
@@ -289,11 +785,11 @@ describe("Env integration", function() {
289
785
 
290
786
  beforeEach(function() {
291
787
  originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
292
- jasmine.getEnv().clock.install();
788
+ jasmine.clock().install();
293
789
  });
294
790
 
295
791
  afterEach(function() {
296
- jasmine.getEnv().clock.uninstall();
792
+ jasmine.clock().uninstall();
297
793
  j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
298
794
  });
299
795
 
@@ -315,14 +811,268 @@ describe("Env integration", function() {
315
811
 
316
812
  env.it("async spec that doesn't call done", function(underTestCallback) {
317
813
  env.expect(true).toBeTruthy();
318
- jasmine.getEnv().clock.tick(8416);
814
+ jasmine.clock().tick(8416);
815
+ });
816
+
817
+ env.execute();
818
+ });
819
+
820
+ it("should wait a specified interval before failing beforeAll's and their associated specs that haven't called done", function(done) {
821
+ var env = new j$.Env(),
822
+ reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
823
+
824
+ reporter.jasmineDone.and.callFake(function() {
825
+ expect(reporter.specDone.calls.count()).toEqual(2);
826
+ expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
827
+ expect(reporter.specDone.calls.argsFor(1)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
828
+ done();
829
+ });
830
+
831
+ env.addReporter(reporter);
832
+ j$.DEFAULT_TIMEOUT_INTERVAL = 1290;
833
+
834
+ env.beforeAll(function(done) {
835
+ jasmine.clock().tick(1290);
836
+ });
837
+
838
+ env.it("spec that will be failed", function() {
839
+ });
840
+
841
+ env.describe("nesting", function() {
842
+ env.it("another spec to fail", function() {
843
+ });
844
+ });
845
+
846
+ env.execute();
847
+ });
848
+
849
+ it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
850
+ var env = new j$.Env(),
851
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
852
+
853
+ reporter.jasmineDone.and.callFake(function() {
854
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
855
+ (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
856
+ ]);
857
+ done();
858
+ });
859
+
860
+ env.addReporter(reporter);
861
+ j$.DEFAULT_TIMEOUT_INTERVAL = 3000;
862
+
863
+ env.describe('my suite', function() {
864
+ env.it('my spec', function() {
865
+ });
866
+
867
+ env.afterAll(function(innerDone) {
868
+ jasmine.clock().tick(3001);
869
+ innerDone();
870
+ });
871
+ });
872
+
873
+ env.execute();
874
+ });
875
+
876
+ it('should wait a custom interval before reporting async functions that fail to call done', function(done) {
877
+ var env = new j$.Env(),
878
+ reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']);
879
+
880
+ reporter.jasmineDone.and.callFake(function() {
881
+ expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite beforeAll times out', [
882
+ (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
883
+ ]);
884
+
885
+ expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('suite afterAll', [
886
+ (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
887
+ ]);
888
+
889
+ expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite beforeEach times out', [
890
+ (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
891
+ ]);
892
+
893
+ expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite afterEach times out', [
894
+ (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
895
+ ]);
896
+
897
+ expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite it times out', [
898
+ (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
899
+ ]);
900
+
901
+ done();
902
+ });
903
+
904
+ env.addReporter(reporter);
905
+ j$.DEFAULT_TIMEOUT_INTERVAL = 10000;
906
+
907
+ env.describe('suite', function() {
908
+ env.describe('beforeAll', function() {
909
+ env.beforeAll(function(innerDone) {
910
+ jasmine.clock().tick(5001);
911
+ innerDone();
912
+ }, 5000);
913
+
914
+ env.it('times out', function() {});
915
+ });
916
+
917
+ env.describe('afterAll', function() {
918
+ env.afterAll(function(innerDone) {
919
+ jasmine.clock().tick(2001);
920
+ innerDone();
921
+ }, 2000);
922
+
923
+ env.it('times out', function() {});
924
+ });
925
+
926
+ env.describe('beforeEach', function() {
927
+ env.beforeEach(function(innerDone) {
928
+ jasmine.clock().tick(1001);
929
+ innerDone();
930
+ }, 1000);
931
+
932
+ env.it('times out', function() {});
933
+ });
934
+
935
+ env.describe('afterEach', function() {
936
+ env.afterEach(function(innerDone) {
937
+ jasmine.clock().tick(4001);
938
+ innerDone();
939
+ }, 4000);
940
+
941
+ env.it('times out', function() {});
942
+ });
943
+
944
+ env.it('it times out', function(innerDone) {
945
+ jasmine.clock().tick(6001);
946
+ innerDone();
947
+ }, 6000);
948
+ });
949
+
950
+ env.execute();
951
+ });
952
+
953
+ it('explicitly fails an async spec', function(done) {
954
+ var env = new j$.Env(),
955
+ specDone = jasmine.createSpy('specDone');
956
+
957
+ env.addReporter({
958
+ specDone: specDone,
959
+ specStarted: function() {
960
+ jasmine.clock().tick(1);
961
+ },
962
+ jasmineDone: function() {
963
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
964
+ description: 'has a default message',
965
+ failedExpectations: [jasmine.objectContaining({
966
+ message: 'Failed'
967
+ })]
968
+ }));
969
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
970
+ description: 'specifies a message',
971
+ failedExpectations: [jasmine.objectContaining({
972
+ message: 'Failed: messy message'
973
+ })]
974
+ }));
975
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
976
+ description: 'fails via the done callback',
977
+ failedExpectations: [jasmine.objectContaining({
978
+ message: 'Failed: done failed'
979
+ })]
980
+ }));
981
+ expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
982
+ description: 'has a message from an Error',
983
+ failedExpectations: [jasmine.objectContaining({
984
+ message: 'Failed: error message'
985
+ })]
986
+ }));
987
+ done();
988
+ }
989
+ });
990
+
991
+ env.describe('failing', function() {
992
+ env.it('has a default message', function(innerDone) {
993
+ setTimeout(function() {
994
+ env.fail();
995
+ innerDone();
996
+ }, 1);
997
+ });
998
+
999
+ env.it('specifies a message', function(innerDone) {
1000
+ setTimeout(function() {
1001
+ env.fail('messy message');
1002
+ innerDone();
1003
+ }, 1);
1004
+ });
1005
+
1006
+ env.it('fails via the done callback', function(innerDone) {
1007
+ setTimeout(function() {
1008
+ innerDone.fail('done failed');
1009
+ }, 1);
1010
+ });
1011
+
1012
+ env.it('has a message from an Error', function(innerDone) {
1013
+ setTimeout(function() {
1014
+ env.fail(new Error('error message'));
1015
+ innerDone();
1016
+ }, 1);
1017
+ });
1018
+ });
1019
+
1020
+ env.execute();
1021
+ });
1022
+ });
1023
+
1024
+ describe('focused tests', function() {
1025
+ it('should only run the focused tests', function(done) {
1026
+ var env = new j$.Env(),
1027
+ calls = [];
1028
+
1029
+ var assertions = function() {
1030
+ expect(calls).toEqual(['focused']);
1031
+ done();
1032
+ };
1033
+
1034
+ env.addReporter({jasmineDone: assertions});
1035
+
1036
+ env.describe('a suite', function() {
1037
+ env.fit('is focused', function() {
1038
+ calls.push('focused');
1039
+ });
1040
+
1041
+ env.it('is not focused', function() {
1042
+ calls.push('freakout');
1043
+ })
1044
+ });
1045
+
1046
+ env.execute();
1047
+ });
1048
+
1049
+ it('should only run focused suites', function(){
1050
+ var env = new j$.Env(),
1051
+ calls = [];
1052
+
1053
+ var assertions = function() {
1054
+ expect(calls).toEqual(['focused']);
1055
+ done();
1056
+ };
1057
+
1058
+ env.addReporter({jasmineDone: assertions});
1059
+
1060
+ env.fdescribe('a focused suite', function() {
1061
+ env.it('is focused', function() {
1062
+ calls.push('focused');
1063
+ });
1064
+ });
1065
+
1066
+ env.describe('a regular suite', function() {
1067
+ env.it('is not focused', function() {
1068
+ calls.push('freakout');
1069
+ })
319
1070
  });
320
1071
 
321
1072
  env.execute();
322
1073
  });
323
1074
  });
324
1075
 
325
- // TODO: something is wrong with this spec
326
1076
  it("should report as expected", function(done) {
327
1077
  var env = new j$.Env(),
328
1078
  reporter = jasmine.createSpyObj('fakeReporter', [
@@ -388,11 +1138,7 @@ describe("Env integration", function() {
388
1138
  it("Custom equality testers should be per spec", function(done) {
389
1139
  var env = new j$.Env({global: { setTimeout: setTimeout }}),
390
1140
  reporter = jasmine.createSpyObj('fakeReporter', [
391
- "jasmineStarted",
392
1141
  "jasmineDone",
393
- "suiteStarted",
394
- "suiteDone",
395
- "specStarted",
396
1142
  "specDone"
397
1143
  ]);
398
1144
 
@@ -422,30 +1168,42 @@ describe("Env integration", function() {
422
1168
  env.execute();
423
1169
  });
424
1170
 
425
- it("Custom matchers should be per spec", function() {
1171
+ it("Custom equality testers should be per suite", function(done) {
426
1172
  var env = new j$.Env({global: { setTimeout: setTimeout }}),
427
- matchers = {
428
- toFoo: function() {}
429
- },
430
1173
  reporter = jasmine.createSpyObj('fakeReporter', [
431
- "jasmineStarted",
432
1174
  "jasmineDone",
433
- "suiteStarted",
434
- "suiteDone",
435
- "specStarted",
436
1175
  "specDone"
437
1176
  ]);
438
1177
 
1178
+ reporter.jasmineDone.and.callFake(function() {
1179
+ var firstSpecResult = reporter.specDone.calls.first().args[0],
1180
+ secondSpecResult = reporter.specDone.calls.argsFor(0)[0],
1181
+ thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
1182
+
1183
+ expect(firstSpecResult.status).toEqual("passed");
1184
+ expect(secondSpecResult.status).toEqual("passed");
1185
+ expect(thirdSpecResult.status).toEqual("failed");
1186
+
1187
+ done();
1188
+ });
1189
+
439
1190
  env.addReporter(reporter);
440
1191
 
441
- env.describe("testing custom matchers", function() {
442
- env.it("with a custom matcher", function() {
443
- env.addMatchers(matchers);
444
- expect(env.expect().toFoo).toBeDefined();
1192
+ env.describe("testing custom equality testers", function() {
1193
+ env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; }); });
1194
+
1195
+ env.it("with a custom tester", function() {
1196
+ env.expect("a").toEqual("b");
445
1197
  });
446
1198
 
447
- env.it("without a custom matcher", function() {
448
- expect(env.expect().toFoo).toBeUndefined();
1199
+ env.it("with the same custom tester", function() {
1200
+ env.expect("a").toEqual("b");
1201
+ });
1202
+ });
1203
+
1204
+ env.describe("another suite", function() {
1205
+ env.it("without the custom tester", function(){
1206
+ env.expect("a").toEqual("b");
449
1207
  });
450
1208
  });
451
1209
 
@@ -455,11 +1213,7 @@ describe("Env integration", function() {
455
1213
  it("Custom equality testers for toContain should be per spec", function(done) {
456
1214
  var env = new j$.Env({global: { setTimeout: setTimeout }}),
457
1215
  reporter = jasmine.createSpyObj('fakeReporter', [
458
- "jasmineStarted",
459
1216
  "jasmineDone",
460
- "suiteStarted",
461
- "suiteDone",
462
- "specStarted",
463
1217
  "specDone"
464
1218
  ]);
465
1219
 
@@ -482,7 +1236,7 @@ describe("Env integration", function() {
482
1236
  });
483
1237
 
484
1238
  env.it("without a custom tester", function() {
485
- env.expect("a").toContain("b");
1239
+ env.expect(["a"]).toContain("b");
486
1240
  });
487
1241
  });
488
1242
 
@@ -502,5 +1256,166 @@ describe("Env integration", function() {
502
1256
 
503
1257
  env.execute();
504
1258
  });
505
- });
506
1259
 
1260
+ it("Custom equality testers for toContain should be per suite", function(done) {
1261
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
1262
+ reporter = jasmine.createSpyObj('fakeReporter', [
1263
+ "jasmineDone",
1264
+ "specDone"
1265
+ ]);
1266
+
1267
+ reporter.jasmineDone.and.callFake(function() {
1268
+ var firstSpecResult = reporter.specDone.calls.first().args[0],
1269
+ secondSpecResult = reporter.specDone.calls.argsFor(1)[0],
1270
+ thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
1271
+
1272
+ expect(firstSpecResult.status).toEqual("passed");
1273
+ expect(secondSpecResult.status).toEqual("passed");
1274
+ expect(thirdSpecResult.status).toEqual("failed");
1275
+
1276
+ done();
1277
+ });
1278
+
1279
+ env.addReporter(reporter);
1280
+
1281
+ env.describe("testing custom equality testers", function() {
1282
+ env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; })});
1283
+
1284
+ env.it("with a custom tester", function() {
1285
+ env.expect(["a"]).toContain("b");
1286
+ });
1287
+
1288
+ env.it("also with the custom tester", function() {
1289
+ env.expect(["a"]).toContain("b");
1290
+ });
1291
+ });
1292
+
1293
+ env.describe("another suite", function() {
1294
+ env.it("without the custom tester", function() {
1295
+ env.expect(["a"]).toContain("b");
1296
+ });
1297
+ });
1298
+
1299
+ env.execute();
1300
+ });
1301
+
1302
+ it("Custom matchers should be per spec", function(done) {
1303
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
1304
+ matchers = {
1305
+ toFoo: function() {}
1306
+ };
1307
+
1308
+ env.describe("testing custom matchers", function() {
1309
+ env.it("with a custom matcher", function() {
1310
+ env.addMatchers(matchers);
1311
+ expect(env.expect().toFoo).toBeDefined();
1312
+ });
1313
+
1314
+ env.it("without a custom matcher", function() {
1315
+ expect(env.expect().toFoo).toBeUndefined();
1316
+ });
1317
+ });
1318
+
1319
+ env.addReporter({jasmineDone: done});
1320
+
1321
+ env.execute();
1322
+ });
1323
+
1324
+ it("Custom matchers should be per suite", function(done) {
1325
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
1326
+ matchers = {
1327
+ toFoo: function() {}
1328
+ };
1329
+
1330
+ env.describe("testing custom matchers", function() {
1331
+ env.beforeAll(function() { env.addMatchers(matchers); });
1332
+
1333
+ env.it("with a custom matcher", function() {
1334
+ expect(env.expect().toFoo).toBeDefined();
1335
+ });
1336
+
1337
+ env.it("with the same custom matcher", function() {
1338
+ expect(env.expect().toFoo).toBeDefined();
1339
+ });
1340
+ });
1341
+
1342
+ env.describe("another suite", function() {
1343
+ env.it("no longer has the custom matcher", function() {
1344
+ expect(env.expect().toFoo).not.toBeDefined();
1345
+ });
1346
+ });
1347
+
1348
+ env.addReporter({jasmineDone: done});
1349
+
1350
+ env.execute();
1351
+ });
1352
+
1353
+ it('throws an exception if you try to create a spy outside of a runnable', function (done) {
1354
+ var env = new j$.Env(),
1355
+ obj = {fn: function () {}},
1356
+ exception;
1357
+
1358
+ env.describe("a suite", function () {
1359
+ try {
1360
+ env.spyOn(obj, 'fn');
1361
+ } catch(e) {
1362
+ exception = e;
1363
+ }
1364
+ });
1365
+
1366
+ var assertions = function() {
1367
+ expect(exception.message).toBe('Spies must be created in a before function or a spec');
1368
+ done();
1369
+ };
1370
+
1371
+ env.addReporter({jasmineDone: assertions});
1372
+
1373
+ env.execute();
1374
+ });
1375
+
1376
+ it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
1377
+ var env = new j$.Env(),
1378
+ obj = {fn: function () {}},
1379
+ exception;
1380
+
1381
+ env.describe("a suite", function () {
1382
+ try {
1383
+ env.addMatchers({myMatcher: function(actual,expected){return false;}});
1384
+ } catch(e) {
1385
+ exception = e;
1386
+ }
1387
+ });
1388
+
1389
+ var assertions = function() {
1390
+ expect(exception.message).toBe('Matchers must be added in a before function or a spec');
1391
+ done();
1392
+ };
1393
+
1394
+ env.addReporter({jasmineDone: assertions});
1395
+
1396
+ env.execute();
1397
+ });
1398
+
1399
+ it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
1400
+ var env = new j$.Env(),
1401
+ obj = {fn: function () {}},
1402
+ exception;
1403
+
1404
+ env.describe("a suite", function () {
1405
+ try {
1406
+ env.addCustomEqualityTester(function(first, second) {return true;});
1407
+ } catch(e) {
1408
+ exception = e;
1409
+ }
1410
+ });
1411
+
1412
+ var assertions = function() {
1413
+ expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec');
1414
+ done();
1415
+ };
1416
+
1417
+ env.addReporter({jasmineDone: assertions});
1418
+
1419
+ env.execute();
1420
+ });
1421
+ });