jasmine-core 2.0.0.rc3 → 2.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/lib/console/console.js +160 -0
  2. data/lib/jasmine-core/boot.js +84 -8
  3. data/lib/jasmine-core/boot/boot.js +84 -8
  4. data/lib/jasmine-core/jasmine-html.js +6 -3
  5. data/lib/jasmine-core/jasmine.js +236 -260
  6. data/lib/jasmine-core/spec/core/AnySpec.js +1 -1
  7. data/lib/jasmine-core/spec/core/ClockSpec.js +0 -20
  8. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +149 -96
  9. data/lib/jasmine-core/spec/core/EnvSpec.js +7 -39
  10. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +13 -19
  11. data/lib/jasmine-core/spec/core/ExpectationSpec.js +74 -1
  12. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +0 -1
  13. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +1 -1
  14. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +28 -20
  15. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +1 -1
  16. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +0 -1
  17. data/lib/jasmine-core/spec/core/SpecSpec.js +2 -11
  18. data/lib/jasmine-core/spec/core/SuiteSpec.js +2 -50
  19. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +13 -1
  20. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +4 -4
  21. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +3 -2
  22. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +1 -1
  23. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +0 -1
  24. data/lib/jasmine-core/spec/html/QueryStringSpec.js +1 -1
  25. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +1 -1
  26. data/lib/jasmine-core/spec/node_suite.js +13 -11
  27. data/lib/jasmine-core/spec/support/dev_boot.js +17 -6
  28. data/lib/jasmine-core/version.rb +1 -1
  29. metadata +41 -13
  30. checksums.yaml +0 -7
@@ -42,4 +42,4 @@ describe("Any", function() {
42
42
  expect(any.jasmineToString()).toMatch('<jasmine.any');
43
43
  });
44
44
 
45
- });
45
+ });
@@ -341,24 +341,4 @@ describe("Clock (acceptance)", function() {
341
341
  clock.tick();
342
342
  expect(delayedFn2).toHaveBeenCalled();
343
343
  });
344
-
345
- it("calls the global clearTimeout correctly when not installed", function() {
346
- var delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['clearTimeout']),
347
- global = jasmine.getGlobal(),
348
- clock = new j$.Clock(global, delayedFunctionScheduler);
349
-
350
- expect(function() {
351
- clock.clearTimeout(123)
352
- }).not.toThrow();
353
- });
354
-
355
- it("calls the global clearTimeout correctly when not installed", function() {
356
- var delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['clearTimeout']),
357
- global = jasmine.getGlobal(),
358
- clock = new j$.Clock(global, delayedFunctionScheduler);
359
-
360
- expect(function() {
361
- clock.clearInterval(123)
362
- }).not.toThrow();
363
- });
364
344
  });
@@ -1,96 +1,149 @@
1
- ////TODO: matchers should be add-able to the env, not to the spec.
2
- //describe("Custom Matchers", function() {
3
- // var env;
4
- // var fakeTimer;
5
- //
6
- // beforeEach(function() {
7
- // env = new jasmine.Env();
8
- // env.updateInterval = 0;
9
- // });
10
- //
11
- // it("should be easy to add more matchers local to a spec, suite, etc.", function() {
12
- // var spec1, spec2, spec1Matcher, spec2Matcher;
13
- // var suite = env.describe('some suite', function() {
14
- // env.beforeEach(function() {
15
- // this.addMatchers({
16
- // matcherForSuite: function(expected) {
17
- // this.message = "matcherForSuite: actual: " + this.actual + "; expected: " + expected;
18
- // return true;
19
- // }
20
- // });
21
- // });
22
- //
23
- // spec1 = env.it('spec with an expectation').runs(function () {
24
- // this.addMatchers({
25
- // matcherForSpec: function(expected) {
26
- // this.message = "matcherForSpec: actual: " + this.actual + "; expected: " + expected;
27
- // return true;
28
- // }
29
- // });
30
- // spec1Matcher = this.expect("xxx");
31
- // });
32
- //
33
- // spec2 = env.it('spec with failing expectation').runs(function () {
34
- // spec2Matcher = this.expect("yyy");
35
- // });
36
- // });
37
- //
38
- // suite.execute();
39
- //
40
- // spec1Matcher.matcherForSuite("expected");
41
- // expect(spec1Matcher.message).toEqual("matcherForSuite: actual: xxx; expected: expected");
42
- // spec1Matcher.matcherForSpec("expected");
43
- // expect(spec1Matcher.message).toEqual("matcherForSpec: actual: xxx; expected: expected");
44
- //
45
- // spec2Matcher.matcherForSuite("expected");
46
- // expect(spec2Matcher.message).toEqual("matcherForSuite: actual: yyy; expected: expected");
47
- // expect(spec2Matcher.matcherForSpec).toBe(jasmine.undefined);
48
- // });
49
- //
50
- // it("should generate messages with the same rules as for regular matchers when this.report() is not called", function() {
51
- // var spec;
52
- // var suite = env.describe('some suite', function() {
53
- // spec = env.it('spec with an expectation').runs(function () {
54
- // this.addMatchers({
55
- // toBeTrue: function() {
56
- // return this.actual === true;
57
- // }
58
- // });
59
- // this.expect(true).toBeTrue();
60
- // this.expect(false).toBeTrue();
61
- // });
62
- // });
63
- //
64
- // suite.execute();
65
- //
66
- // var results = spec.results().getItems();
67
- // expect(results[0].message).toEqual("Passed.");
68
- // expect(results[1].message).toEqual("Expected false to be true.");
69
- // });
70
- //
71
- // it("should pass args", function() {
72
- // var matcherCallArgs = [];
73
- // var spec;
74
- // var suite = env.describe('some suite', function() {
75
- // spec = env.it('spec with an expectation').runs(function () {
76
- // this.addMatchers({
77
- // toBeTrue: function() {
78
- // matcherCallArgs.push(jasmine.util.argsToArray(arguments));
79
- // return this.actual === true;
80
- // }
81
- // });
82
- // this.expect(true).toBeTrue();
83
- // this.expect(false).toBeTrue('arg');
84
- // this.expect(true).toBeTrue('arg1', 'arg2');
85
- // });
86
- // });
87
- //
88
- // suite.execute();
89
- // var results = spec.results().getItems();
90
- // expect(results[0].expected).toEqual(jasmine.undefined);
91
- // expect(results[1].expected).toEqual('arg');
92
- // expect(results[2].expected).toEqual(['arg1', 'arg2']);
93
- //
94
- // expect(matcherCallArgs).toEqual([[], ['arg'], ['arg1', 'arg2']]);
95
- // });
96
- //});
1
+ describe("Custom Matchers (Integration)", function() {
2
+ var env;
3
+ var fakeTimer;
4
+
5
+ beforeEach(function() {
6
+ env = new j$.Env();
7
+ });
8
+
9
+ it("allows adding more matchers local to a spec", function(done) {
10
+ env.it('spec defining a custom matcher', function() {
11
+ env.addMatchers({
12
+ matcherForSpec: function() {
13
+ return {
14
+ compare: function(actual, expected) {
15
+ return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected };
16
+ }
17
+ }
18
+ }
19
+ });
20
+
21
+ env.expect("zzz").matcherForSpec("yyy");
22
+ });
23
+
24
+ env.it("spec without custom matcher defined", function() {
25
+ expect(env.expect("zzz").matcherForSpec).toBeUndefined();
26
+ });
27
+
28
+ var specDoneSpy = jasmine.createSpy("specDoneSpy");
29
+ var expectations = function() {
30
+ var firstSpecResult = specDoneSpy.calls.first().args[0];
31
+ expect(firstSpecResult.status).toEqual("failed");
32
+ expect(firstSpecResult.failedExpectations[0].message).toEqual("matcherForSpec: actual: zzz; expected: yyy");
33
+ done();
34
+ };
35
+ env.addReporter({ specDone:specDoneSpy, jasmineDone: expectations});
36
+
37
+ env.execute();
38
+ });
39
+
40
+ it("passes the spec if the custom matcher passes", function(done) {
41
+ env.addMatchers({
42
+ toBeReal: function() {
43
+ return { compare: function() { return { pass: true }; } };
44
+ }
45
+ });
46
+
47
+ env.it("spec using custom matcher", function() {
48
+ env.expect(true).toBeReal();
49
+ });
50
+
51
+ var specExpectations = function(result) {
52
+ expect(result.status).toEqual('passed');
53
+ };
54
+
55
+ env.addReporter({ specDone: specExpectations, jasmineDone: done });
56
+ env.execute();
57
+ });
58
+
59
+ it("uses the negative compare function for a negative comparison, if provided", function(done) {
60
+ env.addMatchers({
61
+ toBeReal: function() {
62
+ return {
63
+ compare: function() { return { pass: true }; },
64
+ negativeCompare: function() { return { pass: true }; }
65
+ };
66
+ }
67
+ });
68
+
69
+ env.it("spec with custom negative comparison matcher", function() {
70
+ env.expect(true).not.toBeReal();
71
+ });
72
+
73
+ var specExpectations = function(result) {
74
+ expect(result.status).toEqual('passed');
75
+ }
76
+
77
+ env.addReporter({ specDone: specExpectations, jasmineDone: done });
78
+ env.execute();
79
+ });
80
+
81
+ it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
82
+ env.addMatchers({
83
+ toBeReal: function() {
84
+ return {
85
+ compare: function() {
86
+ return { pass: false };
87
+ }
88
+ }
89
+ }
90
+ });
91
+
92
+ env.it('spec with an expectation', function() {
93
+ env.expect("a").toBeReal();
94
+ });
95
+
96
+ var specExpectations = function(result) {
97
+ expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
98
+ };
99
+
100
+ env.addReporter({ specDone: specExpectations, jasmineDone: done });
101
+ env.execute();
102
+ });
103
+
104
+ it("passes the expected and actual arguments to the comparison function", function(done) {
105
+ var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
106
+ env.addMatchers({
107
+ toBeReal: function() {
108
+ return { compare: argumentSpy };
109
+ }
110
+ });
111
+
112
+ env.it('spec with an expectation', function () {
113
+ env.expect(true).toBeReal();
114
+ env.expect(true).toBeReal("arg");
115
+ env.expect(true).toBeReal("arg1", "arg2");
116
+ });
117
+
118
+ var specExpectations = function() {
119
+ expect(argumentSpy).toHaveBeenCalledWith(true);
120
+ expect(argumentSpy).toHaveBeenCalledWith(true, "arg");
121
+ expect(argumentSpy).toHaveBeenCalledWith(true, "arg1", "arg2");
122
+ };
123
+
124
+ env.addReporter({ specDone: specExpectations, jasmineDone: done });
125
+ env.execute();
126
+ });
127
+
128
+ it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) {
129
+ var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; },
130
+ argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
131
+ customEqualityFn = function() { return true; };
132
+
133
+ env.addCustomEqualityTester(customEqualityFn);
134
+ env.addMatchers({
135
+ toBeReal: argumentSpy
136
+ });
137
+
138
+ env.it("spec with expectation", function() {
139
+ env.expect(true).toBeReal();
140
+ });
141
+
142
+ var specExpectations = function() {
143
+ expect(argumentSpy).toHaveBeenCalledWith(j$.matchersUtil, [customEqualityFn]);
144
+ };
145
+
146
+ env.addReporter({ specDone: specExpectations, jasmineDone: done });
147
+ env.execute();
148
+ });
149
+ });
@@ -3,29 +3,6 @@ describe("Env", function() {
3
3
  var env;
4
4
  beforeEach(function() {
5
5
  env = new j$.Env();
6
- env.updateInterval = 0;
7
- });
8
-
9
- describe('ids', function() {
10
- it('nextSpecId should return consecutive integers, starting at 0', function() {
11
- expect(env.nextSpecId()).toEqual('spec0');
12
- expect(env.nextSpecId()).toEqual('spec1');
13
- expect(env.nextSpecId()).toEqual('spec2');
14
- });
15
- });
16
-
17
- describe("reporting", function() {
18
- var fakeReporter;
19
-
20
- beforeEach(function() {
21
- fakeReporter = jasmine.createSpyObj("fakeReporter", ["jasmineStarted"]);
22
- });
23
-
24
- it("should allow reporters to be registered", function() {
25
- env.addReporter(fakeReporter);
26
- env.reporter.jasmineStarted();
27
- expect(fakeReporter.jasmineStarted).toHaveBeenCalled();
28
- });
29
6
  });
30
7
 
31
8
  it('removes all spies when env is executed', function(done) {
@@ -107,21 +84,6 @@ describe("Env", function() {
107
84
  });
108
85
  });
109
86
 
110
- describe("#catchException", function() {
111
- it("returns true if the exception is a pending spec exception", function() {
112
- env.catchExceptions(false);
113
-
114
- expect(env.catchException(new Error(j$.Spec.pendingSpecExceptionMessage))).toBe(true);
115
- });
116
-
117
- it("returns false if the exception is not a pending spec exception and not catching exceptions", function() {
118
- env.catchExceptions(false);
119
-
120
- expect(env.catchException(new Error("external error"))).toBe(false);
121
- expect(env.catchException(new Error(j$.Spec.pendingSpecExceptionMessage))).toBe(true);
122
- });
123
- });
124
-
125
87
  describe("#pending", function() {
126
88
  it("throws the Pending Spec exception", function() {
127
89
  expect(function() {
@@ -130,6 +92,12 @@ describe("Env", function() {
130
92
  });
131
93
  });
132
94
 
95
+ describe("#topSuite", function() {
96
+ it("returns the Jasmine top suite for users to traverse the spec tree", function() {
97
+ var suite = env.topSuite();
98
+ expect(suite.description).toEqual('Jasmine__TopLevel__Suite');
99
+ });
100
+ });
133
101
  });
134
102
 
135
103
  // TODO: move these into a separate file
@@ -356,6 +324,7 @@ describe("Env integration", function() {
356
324
  env.clock.install();
357
325
  env.clock.setTimeout(delayedFunctionForMockClock, 100);
358
326
  env.clock.tick(100);
327
+ env.clock.uninstall();
359
328
  });
360
329
  env.it("test without mock clock", function() {
361
330
  env.clock.setTimeout(delayedFunctionForGlobalClock, 100);
@@ -444,7 +413,6 @@ describe("Env integration", function() {
444
413
  });
445
414
  var suiteResult = reporter.suiteStarted.calls.first().args[0];
446
415
  expect(suiteResult.description).toEqual("A Suite");
447
- expect(reporter.jasmineDone).toHaveBeenCalled();
448
416
 
449
417
  done();
450
418
  });
@@ -3,22 +3,20 @@ describe('Exceptions:', function() {
3
3
 
4
4
  beforeEach(function() {
5
5
  env = new j$.Env();
6
- env.updateInterval = 0;
7
6
  });
8
7
 
9
8
  describe('with break on exception', function() {
10
9
  it('should not catch the exception', function() {
11
10
  env.catchExceptions(false);
12
- var suite = env.describe('suite for break on exceptions', function() {
11
+ env.describe('suite for break on exceptions', function() {
13
12
  env.it('should break when an exception is thrown', function() {
14
13
  throw new Error('I should hit a breakpoint!');
15
14
  });
16
15
  });
17
- var runner = env.currentRunner();
18
16
  var dont_change = 'I will never change!';
19
17
 
20
18
  try {
21
- suite.execute();
19
+ env.execute();
22
20
  dont_change = 'oops I changed';
23
21
  }
24
22
  catch (e) {}
@@ -29,36 +27,32 @@ describe('Exceptions:', function() {
29
27
 
30
28
  describe("with catch on exception", function() {
31
29
  it('should handle exceptions thrown, but continue', function() {
32
- var ranSecondTest = false,
33
- suite = env.describe('Suite for handles exceptions', function () {
30
+ var secondTest = jasmine.createSpy('second test');
31
+ env.describe('Suite for handles exceptions', function () {
34
32
  env.it('should be a test that fails because it throws an exception', function() {
35
33
  throw new Error();
36
34
  });
37
- env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
38
- ranSecondTest = true;
39
- });
35
+ env.it('should be a passing test that runs after exceptions are thrown from a async test', secondTest);
40
36
  });
41
37
 
42
- suite.execute();
43
- expect(ranSecondTest).toBe(true);
38
+ env.execute();
39
+ expect(secondTest).toHaveBeenCalled();
44
40
  });
45
41
 
46
42
  it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
47
- var ranSecondDescribe = false, suite, suite2, runner = env.currentRunner();
48
- suite = env.describe("a suite that throws an exception", function () {
43
+ var secondDescribe = jasmine.createSpy("second describe");
44
+ env.describe("a suite that throws an exception", function () {
49
45
  env.it("is a test that should pass", function () {
50
46
  this.expect(true).toEqual(true);
51
47
  });
52
48
 
53
49
  throw new Error("top level error");
54
50
  });
55
- suite2 = env.describe("a suite that doesn't throw an exception", function () {
56
- ranSecondDescribe = true;
57
- });
51
+ env.describe("a suite that doesn't throw an exception", secondDescribe);
58
52
 
59
- runner.execute();
60
- expect(ranSecondDescribe).toBe(true);
53
+ env.execute();
54
+ expect(secondDescribe).toHaveBeenCalled();
61
55
  });
62
56
  });
63
-
64
57
  });
58
+
@@ -317,4 +317,77 @@ describe("Expectation", function() {
317
317
  message: "I am a custom message"
318
318
  });
319
319
  });
320
- });
320
+
321
+ it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
322
+ var matchers = {
323
+ toFoo: function() {
324
+ return {
325
+ compare: function() { return { pass: true }; },
326
+ negativeCompare: function() { return { pass: true }; }
327
+ };
328
+ }
329
+ },
330
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
331
+ actual = "an actual",
332
+ expectation;
333
+
334
+ j$.Expectation.addMatchers(matchers);
335
+
336
+ expectation = new j$.Expectation({
337
+ matchers: matchers,
338
+ actual: "an actual",
339
+ addExpectationResult: addExpectationResult,
340
+ isNot: true
341
+ });
342
+
343
+ expectation.toFoo("hello");
344
+
345
+ expect(addExpectationResult).toHaveBeenCalledWith(true, {
346
+ matcherName: "toFoo",
347
+ passed: true,
348
+ expected: "hello",
349
+ actual: actual,
350
+ message: ""
351
+ });
352
+ });
353
+
354
+ it("reports a failing result and a custom fail message to the spec when the 'not' comparison fails, given a negativeCompare", function() {
355
+ var matchers = {
356
+ toFoo: function() {
357
+ return {
358
+ compare: function() { return { pass: true }; },
359
+ negativeCompare: function() {
360
+ return {
361
+ pass: false,
362
+ message: "I'm a custom message"
363
+ };
364
+ }
365
+ };
366
+ }
367
+ },
368
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
369
+ actual = "an actual",
370
+ expectation;
371
+
372
+ j$.Expectation.addMatchers(matchers);
373
+
374
+ expectation = new j$.Expectation({
375
+ matchers: matchers,
376
+ actual: "an actual",
377
+ addExpectationResult: addExpectationResult,
378
+ isNot: true
379
+ });
380
+
381
+ expectation.toFoo("hello");
382
+
383
+ expect(addExpectationResult).toHaveBeenCalledWith(false, {
384
+ matcherName: "toFoo",
385
+ passed: false,
386
+ expected: "hello",
387
+ actual: actual,
388
+ message: "I'm a custom message"
389
+ });
390
+ });
391
+
392
+ });
393
+