jasmine-core 2.0.0.rc2 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jasmine-core/boot.js +0 -4
  3. data/lib/jasmine-core/boot/boot.js +0 -4
  4. data/lib/jasmine-core/jasmine-html.js +3 -1
  5. data/lib/jasmine-core/jasmine.css +4 -3
  6. data/lib/jasmine-core/jasmine.js +64 -34
  7. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +2 -2
  8. data/lib/jasmine-core/spec/core/ClockSpec.js +168 -118
  9. data/lib/jasmine-core/spec/core/EnvSpec.js +133 -48
  10. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +1 -1
  11. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +2 -2
  12. data/lib/jasmine-core/spec/core/ExpectationSpec.js +2 -2
  13. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +1 -1
  14. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +17 -0
  15. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +6 -6
  16. data/lib/jasmine-core/spec/core/SpecSpec.js +6 -2
  17. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +19 -9
  18. data/lib/jasmine-core/spec/core/TimerSpec.js +2 -2
  19. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +2 -2
  20. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +2 -2
  21. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +7 -12
  22. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +8 -8
  23. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +4 -4
  24. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -11
  25. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +5 -3
  26. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +7 -0
  27. data/lib/jasmine-core/spec/node_suite.js +1 -1
  28. data/lib/jasmine-core/spec/support/dev_boot.js +0 -5
  29. data/lib/jasmine-core/version.rb +1 -1
  30. metadata +16 -107
@@ -8,9 +8,9 @@ describe("Env", function() {
8
8
 
9
9
  describe('ids', function() {
10
10
  it('nextSpecId should return consecutive integers, starting at 0', function() {
11
- expect(env.nextSpecId()).toEqual(0);
12
- expect(env.nextSpecId()).toEqual(1);
13
- expect(env.nextSpecId()).toEqual(2);
11
+ expect(env.nextSpecId()).toEqual('spec0');
12
+ expect(env.nextSpecId()).toEqual('spec1');
13
+ expect(env.nextSpecId()).toEqual('spec2');
14
14
  });
15
15
  });
16
16
 
@@ -27,7 +27,7 @@ describe("Env", function() {
27
27
  expect(fakeReporter.jasmineStarted).toHaveBeenCalled();
28
28
  });
29
29
  });
30
-
30
+
31
31
  it('removes all spies when env is executed', function(done) {
32
32
  originalFoo = function() {},
33
33
  testObj = {
@@ -85,11 +85,11 @@ describe("Env", function() {
85
85
  var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
86
86
 
87
87
  originalFunc = subject.spiedFunc;
88
-
88
+
89
89
  var spy = env.spyOn(subject, 'spiedFunc');
90
90
 
91
91
  expect(subject.spiedFunc).toEqual(spy);
92
-
92
+
93
93
  expect(subject.spiedFunc.calls.any()).toEqual(false);
94
94
  expect(subject.spiedFunc.calls.count()).toEqual(0);
95
95
 
@@ -236,6 +236,106 @@ describe("Env integration", function() {
236
236
  env.execute();
237
237
  });
238
238
 
239
+ it("calls associated befores/specs/afters with the same 'this'", function(done) {
240
+ var env = new j$.Env();
241
+
242
+ env.addReporter({jasmineDone: done});
243
+
244
+ env.describe("tests", function() {
245
+ var firstTimeThrough = true, firstSpecContext, secondSpecContext;
246
+
247
+ env.beforeEach(function() {
248
+ if (firstTimeThrough) {
249
+ firstSpecContext = this;
250
+ } else {
251
+ secondSpecContext = this;
252
+ }
253
+ expect(this).toEqual({});
254
+ });
255
+
256
+ env.it("sync spec", function() {
257
+ expect(this).toBe(firstSpecContext);
258
+ });
259
+
260
+ env.it("another sync spec", function() {
261
+ expect(this).toBe(secondSpecContext);
262
+ });
263
+
264
+ env.afterEach(function() {
265
+ if (firstTimeThrough) {
266
+ expect(this).toBe(firstSpecContext);
267
+ firstTimeThrough = false;
268
+ } else {
269
+ expect(this).toBe(secondSpecContext);
270
+ }
271
+ });
272
+ });
273
+
274
+ env.execute();
275
+ });
276
+
277
+ it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) {
278
+ var env = new j$.Env();
279
+
280
+ env.addReporter({jasmineDone: done});
281
+
282
+ env.describe("with an async spec", function() {
283
+ var specContext;
284
+
285
+ env.beforeEach(function() {
286
+ specContext = this;
287
+ expect(this).toEqual({});
288
+ });
289
+
290
+ env.it("sync spec", function(underTestCallback) {
291
+ expect(this).toBe(specContext);
292
+ underTestCallback();
293
+ });
294
+
295
+ env.afterEach(function() {
296
+ expect(this).toBe(specContext);
297
+ });
298
+ });
299
+
300
+ env.execute();
301
+ });
302
+
303
+ it("Allows specifying which specs and suites to run", function(done) {
304
+ var env = new j$.Env(),
305
+ calls = [],
306
+ suiteCallback = jasmine.createSpy('suite callback'),
307
+ firstSpec,
308
+ secondSuite;
309
+
310
+ var assertions = function() {
311
+ expect(calls).toEqual([
312
+ 'third spec',
313
+ 'first spec'
314
+ ]);
315
+ expect(suiteCallback).toHaveBeenCalled();
316
+ done();
317
+ };
318
+
319
+ env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback});
320
+
321
+ env.describe("first suite", function() {
322
+ firstSpec = env.it("first spec", function() {
323
+ calls.push('first spec');
324
+ });
325
+ env.it("second spec", function() {
326
+ calls.push('second spec');
327
+ });
328
+ });
329
+
330
+ secondSuite = env.describe("second suite", function() {
331
+ env.it("third spec", function() {
332
+ calls.push('third spec');
333
+ });
334
+ });
335
+
336
+ env.execute([secondSuite.id, firstSpec.id]);
337
+ });
338
+
239
339
  it("Mock clock can be installed and used in tests", function(done) {
240
340
  var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
241
341
  delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
@@ -293,52 +393,37 @@ describe("Env integration", function() {
293
393
  });
294
394
 
295
395
  describe("with a mock clock", function() {
296
- beforeEach(function() {
297
- jasmine.getEnv().clock.install();
298
- });
299
-
300
- afterEach(function() {
301
- jasmine.getEnv().clock.uninstall();
302
- });
303
-
304
- it("should not hang on async specs that forget to call done()", function(done) {
305
- var env = new j$.Env(),
306
- reporter = jasmine.createSpyObj('fakeReporter', [
307
- "jasmineStarted",
308
- "jasmineDone",
309
- "suiteStarted",
310
- "suiteDone",
311
- "specStarted",
312
- "specDone"
313
- ]);
314
-
315
- env.addReporter(reporter);
316
-
317
- env.describe("tests", function() {
318
- env.it("async spec that will hang", function(underTestCallback) {
319
- env.expect(true).toBeTruthy();
320
- });
396
+ var originalTimeout;
321
397
 
322
- env.it("after async spec", function() {
323
- env.expect(true).toBeTruthy();
324
- });
325
- });
398
+ beforeEach(function() {
399
+ originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
400
+ jasmine.getEnv().clock.install();
401
+ });
326
402
 
327
- env.execute();
403
+ afterEach(function() {
404
+ jasmine.getEnv().clock.uninstall();
405
+ j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
406
+ });
328
407
 
329
- reporter.jasmineDone.and.callFake(function() {
330
- expect(reporter.jasmineStarted).toHaveBeenCalledWith({
331
- totalSpecsDefined: 2
332
- });
408
+ it("should wait a specified interval before failing specs haven't called done yet", function(done) {
409
+ var env = new j$.Env(),
410
+ reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]);
333
411
 
334
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'passed'}));
335
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
412
+ reporter.specDone.and.callFake(function() {
413
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
414
+ done();
415
+ });
336
416
 
337
- done();
338
- });
417
+ env.addReporter(reporter);
418
+ j$.DEFAULT_TIMEOUT_INTERVAL = 8414;
339
419
 
340
- jasmine.getEnv().clock.tick(60001);
420
+ env.it("async spec that doesn't call done", function(underTestCallback) {
421
+ env.expect(true).toBeTruthy();
422
+ jasmine.getEnv().clock.tick(8414);
341
423
  });
424
+
425
+ env.execute();
426
+ });
342
427
  });
343
428
 
344
429
  // TODO: something is wrong with this spec
@@ -400,9 +485,9 @@ describe("Env integration", function() {
400
485
  });
401
486
  });
402
487
 
403
- expect(topLevelSpec.getFullName()).toBe("my tests are sometimes top level.");
404
- expect(nestedSpec.getFullName()).toBe("my tests are sometimes singly nested.");
405
- expect(doublyNestedSpec.getFullName()).toBe("my tests are sometimes even doubly nested.");
488
+ expect(topLevelSpec.getFullName()).toBe("my tests are sometimes top level");
489
+ expect(nestedSpec.getFullName()).toBe("my tests are sometimes singly nested");
490
+ expect(doublyNestedSpec.getFullName()).toBe("my tests are sometimes even doubly nested");
406
491
  });
407
492
 
408
493
  it("Custom equality testers should be per spec", function(done) {
@@ -1,4 +1,4 @@
1
- xdescribe('Exceptions:', function() {
1
+ describe('Exceptions:', function() {
2
2
  var env;
3
3
 
4
4
  beforeEach(function() {
@@ -16,7 +16,7 @@ describe("buildExpectationResult", function() {
16
16
 
17
17
  it("delegates message formatting to the provided formatter if there was an Error", function() {
18
18
  var fakeError = {message: 'foo'},
19
- messageFormatter = jasmine.createSpy("exception message formatter").and.callReturn(fakeError.message);
19
+ messageFormatter = jasmine.createSpy("exception message formatter").and.returnValue(fakeError.message);
20
20
 
21
21
  var result = j$.buildExpectationResult(
22
22
  {
@@ -31,7 +31,7 @@ describe("buildExpectationResult", function() {
31
31
 
32
32
  it("delegates stack formatting to the provided formatter if there was an Error", function() {
33
33
  var fakeError = {stack: 'foo'},
34
- stackFormatter = jasmine.createSpy("stack formatter").and.callReturn(fakeError.stack);
34
+ stackFormatter = jasmine.createSpy("stack formatter").and.returnValue(fakeError.stack);
35
35
 
36
36
  var result = j$.buildExpectationResult(
37
37
  {
@@ -56,7 +56,7 @@ describe("Expectation", function() {
56
56
 
57
57
  it("wraps matchers's compare functions, passing in matcher dependencies", function() {
58
58
  var fakeCompare = function() { return { pass: true }; },
59
- matcherFactory = jasmine.createSpy("matcher").and.callReturn({ compare: fakeCompare }),
59
+ matcherFactory = jasmine.createSpy("matcher").and.returnValue({ compare: fakeCompare }),
60
60
  matchers = {
61
61
  toFoo: matcherFactory
62
62
  },
@@ -80,7 +80,7 @@ describe("Expectation", function() {
80
80
  });
81
81
 
82
82
  it("wraps matchers's compare functions, passing the actual and expected", function() {
83
- var fakeCompare = jasmine.createSpy('fake-compare').and.callReturn({pass: true}),
83
+ var fakeCompare = jasmine.createSpy('fake-compare').and.returnValue({pass: true}),
84
84
  matchers = {
85
85
  toFoo: function() {
86
86
  return {
@@ -196,7 +196,7 @@ describe("JsApiReporter", function() {
196
196
  timer: timerSpy
197
197
  });
198
198
 
199
- timerSpy.elapsed.and.callReturn(1000);
199
+ timerSpy.elapsed.and.returnValue(1000);
200
200
  reporter.jasmineDone();
201
201
  expect(reporter.executionTime()).toEqual(1000);
202
202
  });
@@ -19,6 +19,23 @@ describe("QueueRunner", function() {
19
19
  expect(calls).toEqual(['fn1', 'fn2']);
20
20
  });
21
21
 
22
+ it("calls each function with a consistent 'this'-- an empty object", function() {
23
+ var fn1 = jasmine.createSpy('fn1'),
24
+ fn2 = jasmine.createSpy('fn2'),
25
+ fn3 = function(done) { asyncContext = this; done(); },
26
+ queueRunner = new j$.QueueRunner({
27
+ fns: [fn1, fn2, fn3]
28
+ }),
29
+ asyncContext;
30
+
31
+ queueRunner.execute();
32
+
33
+ var context = fn1.calls.first().object;
34
+ expect(context).toEqual({});
35
+ expect(fn2.calls.first().object).toBe(context);
36
+ expect(asyncContext).toBe(context);
37
+ });
38
+
22
39
  it("supports asynchronous functions, only advancing to next function after a done() callback", function() {
23
40
  //TODO: it would be nice if spy arity could match the fake, so we could do something like:
24
41
  //createSpy('asyncfn').and.callFake(function(done) {});
@@ -25,11 +25,11 @@ describe("jasmine spec running", function () {
25
25
  });
26
26
  });
27
27
 
28
- expect(it0.id).toEqual(0);
29
- expect(it1.id).toEqual(1);
30
- expect(it2.id).toEqual(2);
31
- expect(it3.id).toEqual(3);
32
- expect(it4.id).toEqual(4);
28
+ expect(it0.id).toEqual('spec0');
29
+ expect(it1.id).toEqual('spec1');
30
+ expect(it2.id).toEqual('spec2');
31
+ expect(it3.id).toEqual('spec3');
32
+ expect(it4.id).toEqual('spec4');
33
33
  });
34
34
 
35
35
  it('nested suites', function (done) {
@@ -305,4 +305,4 @@ describe("jasmine spec running", function () {
305
305
  ));
306
306
 
307
307
  });
308
- });
308
+ });
@@ -36,7 +36,6 @@ describe("Spec", function() {
36
36
 
37
37
  it("should call the start callback on execution", function() {
38
38
  var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
39
- beforesWereCalled = false,
40
39
  startCallback = jasmine.createSpy('startCallback'),
41
40
  spec = new j$.Spec({
42
41
  id: 123,
@@ -48,7 +47,12 @@ describe("Spec", function() {
48
47
 
49
48
  spec.execute();
50
49
 
51
- expect(startCallback).toHaveBeenCalledWith(spec);
50
+ // TODO: due to some issue with the Pretty Printer, this line fails, but the other two pass.
51
+ // This means toHaveBeenCalledWith on IE8 will always be broken.
52
+
53
+ // expect(startCallback).toHaveBeenCalledWith(spec);
54
+ expect(startCallback).toHaveBeenCalled();
55
+ expect(startCallback.calls.first().object).toEqual(spec);
52
56
  });
53
57
 
54
58
  it("should call the start callback on execution but before any befores are called", function() {
@@ -22,7 +22,7 @@ describe("SpyStrategy", function() {
22
22
  });
23
23
 
24
24
  it("allows an original function to be called, passed through the params and returns it's value", function() {
25
- var originalFn = jasmine.createSpy("original").and.callReturn(42),
25
+ var originalFn = jasmine.createSpy("original").and.returnValue(42),
26
26
  spyStrategy = new j$.SpyStrategy({fn: originalFn}),
27
27
  returnValue;
28
28
 
@@ -39,7 +39,7 @@ describe("SpyStrategy", function() {
39
39
  spyStrategy = new j$.SpyStrategy({fn: originalFn}),
40
40
  returnValue;
41
41
 
42
- spyStrategy.callReturn(17);
42
+ spyStrategy.returnValue(17);
43
43
  returnValue = spyStrategy.exec();
44
44
 
45
45
  expect(originalFn).not.toHaveBeenCalled();
@@ -50,15 +50,25 @@ describe("SpyStrategy", function() {
50
50
  var originalFn = jasmine.createSpy("original"),
51
51
  spyStrategy = new j$.SpyStrategy({fn: originalFn});
52
52
 
53
- spyStrategy.callThrow("bar");
53
+ spyStrategy.throwError(new TypeError("bar"));
54
54
 
55
- expect(function() { spyStrategy.exec(); }).toThrow("bar");
55
+ expect(function() { spyStrategy.exec(); }).toThrowError(TypeError, "bar");
56
+ expect(originalFn).not.toHaveBeenCalled();
57
+ });
58
+
59
+ it("allows a non-Error to be thrown, wrapping it into an exception when executed", function() {
60
+ var originalFn = jasmine.createSpy("original"),
61
+ spyStrategy = new j$.SpyStrategy({fn: originalFn});
62
+
63
+ spyStrategy.throwError("bar");
64
+
65
+ expect(function() { spyStrategy.exec(); }).toThrowError(Error, "bar");
56
66
  expect(originalFn).not.toHaveBeenCalled();
57
67
  });
58
68
 
59
69
  it("allows a fake function to be called instead", function() {
60
70
  var originalFn = jasmine.createSpy("original"),
61
- fakeFn = jasmine.createSpy("fake").and.callReturn(67),
71
+ fakeFn = jasmine.createSpy("fake").and.returnValue(67),
62
72
  spyStrategy = new j$.SpyStrategy({fn: originalFn}),
63
73
  returnValue;
64
74
 
@@ -71,7 +81,7 @@ describe("SpyStrategy", function() {
71
81
 
72
82
  it("allows a return to plan stubbing after another strategy", function() {
73
83
  var originalFn = jasmine.createSpy("original"),
74
- fakeFn = jasmine.createSpy("fake").and.callReturn(67),
84
+ fakeFn = jasmine.createSpy("fake").and.returnValue(67),
75
85
  spyStrategy = new j$.SpyStrategy({fn: originalFn}),
76
86
  returnValue;
77
87
 
@@ -89,12 +99,12 @@ describe("SpyStrategy", function() {
89
99
 
90
100
  it("returns the spy after changing the strategy", function(){
91
101
  var spy = {},
92
- spyFn = jasmine.createSpy('spyFn').and.callReturn(spy),
102
+ spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
93
103
  spyStrategy = new j$.SpyStrategy({getSpy: spyFn});
94
104
 
95
105
  expect(spyStrategy.callThrough()).toBe(spy);
96
- expect(spyStrategy.callReturn()).toBe(spy);
97
- expect(spyStrategy.callThrow()).toBe(spy);
106
+ expect(spyStrategy.returnValue()).toBe(spy);
107
+ expect(spyStrategy.throwError()).toBe(spy);
98
108
  expect(spyStrategy.callFake()).toBe(spy);
99
109
  expect(spyStrategy.stub()).toBe(spy);
100
110
  });
@@ -3,10 +3,10 @@ describe("Timer", function() {
3
3
  var fakeNow = jasmine.createSpy('fake Date.now'),
4
4
  timer = new j$.Timer({now: fakeNow});
5
5
 
6
- fakeNow.and.callReturn(100);
6
+ fakeNow.and.returnValue(100);
7
7
  timer.start();
8
8
 
9
- fakeNow.and.callReturn(200);
9
+ fakeNow.and.returnValue(200);
10
10
 
11
11
  expect(timer.elapsed()).toEqual(100);
12
12
  });
@@ -1,7 +1,7 @@
1
1
  describe("toContain", function() {
2
2
  it("delegates to j$.matchersUtil.contains", function() {
3
3
  var util = {
4
- contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
4
+ contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
5
5
  },
6
6
  matcher = j$.matchers.toContain(util);
7
7
 
@@ -12,7 +12,7 @@ describe("toContain", function() {
12
12
 
13
13
  it("delegates to j$.matchersUtil.contains, passing in equality testers if present", function() {
14
14
  var util = {
15
- contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
15
+ contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
16
16
  },
17
17
  customEqualityTesters = ['a', 'b'],
18
18
  matcher = j$.matchers.toContain(util, customEqualityTesters);