jasmine-core 1.3.1 → 2.0.0.rc2

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 (73) hide show
  1. data/lib/jasmine-core.rb +14 -1
  2. data/lib/jasmine-core/boot.js +131 -0
  3. data/lib/jasmine-core/boot/boot.js +109 -0
  4. data/lib/jasmine-core/example/spec/PlayerSpec.js +2 -2
  5. data/lib/jasmine-core/example/spec/SpecHelper.js +14 -8
  6. data/lib/jasmine-core/jasmine-html.js +289 -616
  7. data/lib/jasmine-core/jasmine.css +52 -80
  8. data/lib/jasmine-core/jasmine.js +1972 -2211
  9. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +161 -386
  10. data/lib/jasmine-core/spec/core/AnySpec.js +45 -0
  11. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +105 -0
  12. data/lib/jasmine-core/spec/core/ClockSpec.js +314 -0
  13. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +96 -97
  14. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +179 -0
  15. data/lib/jasmine-core/spec/core/EnvSpec.js +454 -102
  16. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +56 -0
  17. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +15 -126
  18. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
  19. data/lib/jasmine-core/spec/core/ExpectationSpec.js +320 -0
  20. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +150 -38
  21. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +64 -0
  22. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +43 -42
  23. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +147 -0
  24. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +40 -0
  25. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +92 -1075
  26. data/lib/jasmine-core/spec/core/SpecSpec.js +215 -95
  27. data/lib/jasmine-core/spec/core/SpySpec.js +28 -196
  28. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +101 -0
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +216 -106
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +13 -0
  31. data/lib/jasmine-core/spec/core/UtilSpec.js +19 -30
  32. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +219 -0
  33. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +51 -0
  34. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
  35. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
  36. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +19 -0
  37. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
  38. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +36 -0
  39. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
  40. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
  41. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
  42. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +17 -0
  43. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +24 -0
  44. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +28 -0
  45. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +46 -0
  46. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +57 -0
  47. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +34 -0
  48. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +280 -0
  49. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +98 -0
  50. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +19 -0
  51. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +494 -0
  52. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
  53. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +8 -8
  54. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +3 -3
  55. data/lib/jasmine-core/spec/html/QueryStringSpec.js +43 -0
  56. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
  57. data/lib/jasmine-core/spec/node_suite.js +137 -79
  58. data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
  59. data/lib/jasmine-core/spec/support/dev_boot.js +118 -0
  60. data/lib/jasmine-core/version.rb +5 -2
  61. metadata +47 -103
  62. data/lib/jasmine-core/example/SpecRunner.html +0 -54
  63. data/lib/jasmine-core/spec/core/BaseSpec.js +0 -27
  64. data/lib/jasmine-core/spec/core/MatchersSpec.js +0 -1157
  65. data/lib/jasmine-core/spec/core/MockClockSpec.js +0 -38
  66. data/lib/jasmine-core/spec/core/MultiReporterSpec.js +0 -45
  67. data/lib/jasmine-core/spec/core/NestedResultsSpec.js +0 -54
  68. data/lib/jasmine-core/spec/core/QueueSpec.js +0 -23
  69. data/lib/jasmine-core/spec/core/ReporterSpec.js +0 -56
  70. data/lib/jasmine-core/spec/core/RunnerSpec.js +0 -280
  71. data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +0 -118
  72. data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +0 -209
  73. data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +0 -239
@@ -1,97 +1,96 @@
1
- describe("Custom Matchers", function() {
2
- var env;
3
- var fakeTimer;
4
-
5
- beforeEach(function() {
6
- env = new jasmine.Env();
7
- env.updateInterval = 0;
8
- });
9
-
10
- it("should be easy to add more matchers local to a spec, suite, etc.", function() {
11
- var spec1, spec2, spec1Matcher, spec2Matcher;
12
- var suite = env.describe('some suite', function() {
13
- env.beforeEach(function() {
14
- this.addMatchers({
15
- matcherForSuite: function(expected) {
16
- this.message = "matcherForSuite: actual: " + this.actual + "; expected: " + expected;
17
- return true;
18
- }
19
- });
20
- });
21
-
22
- spec1 = env.it('spec with an expectation').runs(function () {
23
- this.addMatchers({
24
- matcherForSpec: function(expected) {
25
- this.message = "matcherForSpec: actual: " + this.actual + "; expected: " + expected;
26
- return true;
27
- }
28
- });
29
- spec1Matcher = this.expect("xxx");
30
- });
31
-
32
- spec2 = env.it('spec with failing expectation').runs(function () {
33
- spec2Matcher = this.expect("yyy");
34
- });
35
- });
36
-
37
- suite.execute();
38
-
39
- spec1Matcher.matcherForSuite("expected");
40
- expect(spec1Matcher.message).toEqual("matcherForSuite: actual: xxx; expected: expected");
41
- spec1Matcher.matcherForSpec("expected");
42
- expect(spec1Matcher.message).toEqual("matcherForSpec: actual: xxx; expected: expected");
43
-
44
- spec2Matcher.matcherForSuite("expected");
45
- expect(spec2Matcher.message).toEqual("matcherForSuite: actual: yyy; expected: expected");
46
- expect(spec2Matcher.matcherForSpec).toBe(jasmine.undefined);
47
- });
48
-
49
- it("should generate messages with the same rules as for regular matchers when this.report() is not called", function() {
50
- var spec;
51
- var suite = env.describe('some suite', function() {
52
- spec = env.it('spec with an expectation').runs(function () {
53
- this.addMatchers({
54
- toBeTrue: function() {
55
- return this.actual === true;
56
- }
57
- });
58
- this.expect(true).toBeTrue();
59
- this.expect(false).toBeTrue();
60
- });
61
- });
62
-
63
- suite.execute();
64
- var passResult = new jasmine.ExpectationResult({passed: true, matcherName: 'toBeTrue',
65
- actual: true, expected: jasmine.undefined, message: "Passed." });
66
- var failResult = new jasmine.ExpectationResult({passed: false, matcherName: 'toBeTrue',
67
- actual: false, expected: jasmine.undefined, message: "Expected false to be true." });
68
- failResult.trace = jasmine.any(Object);
69
- expect(spec.results().getItems()).toEqual([passResult, failResult]);
70
- });
71
-
72
- it("should pass args", function() {
73
- var matcherCallArgs = [];
74
- var spec;
75
- var suite = env.describe('some suite', function() {
76
- spec = env.it('spec with an expectation').runs(function () {
77
- this.addMatchers({
78
- toBeTrue: function() {
79
- matcherCallArgs.push(jasmine.util.argsToArray(arguments));
80
- return this.actual === true;
81
- }
82
- });
83
- this.expect(true).toBeTrue();
84
- this.expect(false).toBeTrue('arg');
85
- this.expect(true).toBeTrue('arg1', 'arg2');
86
- });
87
- });
88
-
89
- suite.execute();
90
- var results = spec.results().getItems();
91
- expect(results[0].expected).toEqual(jasmine.undefined);
92
- expect(results[1].expected).toEqual('arg');
93
- expect(results[2].expected).toEqual(['arg1', 'arg2']);
94
-
95
- expect(matcherCallArgs).toEqual([[], ['arg'], ['arg1', 'arg2']]);
96
- });
97
- });
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
+ //});
@@ -0,0 +1,179 @@
1
+ describe("DelayedFunctionScheduler", function() {
2
+ it("schedules a function for later execution", function() {
3
+ var scheduler = new j$.DelayedFunctionScheduler(),
4
+ fn = jasmine.createSpy('fn');
5
+
6
+ scheduler.scheduleFunction(fn, 0);
7
+
8
+ expect(fn).not.toHaveBeenCalled();
9
+
10
+ scheduler.tick(0);
11
+
12
+ expect(fn).toHaveBeenCalled();
13
+ });
14
+
15
+ it("schedules a string for later execution", function() {
16
+ var scheduler = new j$.DelayedFunctionScheduler(),
17
+ strfn = "horrible = true;";
18
+
19
+ scheduler.scheduleFunction(strfn, 0);
20
+
21
+ scheduler.tick(0);
22
+
23
+ expect(horrible).toEqual(true);
24
+ });
25
+
26
+ it("#tick defaults to 0", function() {
27
+ var scheduler = new j$.DelayedFunctionScheduler(),
28
+ fn = jasmine.createSpy('fn');
29
+
30
+ scheduler.scheduleFunction(fn, 0);
31
+
32
+ expect(fn).not.toHaveBeenCalled();
33
+
34
+ scheduler.tick();
35
+
36
+ expect(fn).toHaveBeenCalled();
37
+ });
38
+
39
+ it("defaults delay to 0", function() {
40
+ var scheduler = new j$.DelayedFunctionScheduler(),
41
+ fn = jasmine.createSpy('fn');
42
+
43
+ scheduler.scheduleFunction(fn);
44
+
45
+ expect(fn).not.toHaveBeenCalled();
46
+
47
+ scheduler.tick(0);
48
+
49
+ expect(fn).toHaveBeenCalled();
50
+ });
51
+
52
+ it("optionally passes params to scheduled functions", function() {
53
+ var scheduler = new j$.DelayedFunctionScheduler(),
54
+ fn = jasmine.createSpy('fn');
55
+
56
+ scheduler.scheduleFunction(fn, 0, ['foo', 'bar']);
57
+
58
+ expect(fn).not.toHaveBeenCalled();
59
+
60
+ scheduler.tick(0);
61
+
62
+ expect(fn).toHaveBeenCalledWith('foo', 'bar');
63
+ });
64
+
65
+ it("scheduled fns can optionally reoccur", function() {
66
+ var scheduler = new j$.DelayedFunctionScheduler(),
67
+ fn = jasmine.createSpy('fn');
68
+
69
+ scheduler.scheduleFunction(fn, 20, [], true);
70
+
71
+ expect(fn).not.toHaveBeenCalled();
72
+
73
+ scheduler.tick(20);
74
+
75
+ expect(fn.calls.count()).toBe(1);
76
+
77
+ scheduler.tick(40);
78
+
79
+ expect(fn.calls.count()).toBe(3);
80
+
81
+ scheduler.tick(21);
82
+
83
+ expect(fn.calls.count()).toBe(4);
84
+
85
+ });
86
+
87
+ it("increments scheduled fns ids unless one is passed", function() {
88
+ var scheduler = new j$.DelayedFunctionScheduler();
89
+
90
+ expect(scheduler.scheduleFunction(function() {
91
+ }, 0)).toBe(1);
92
+ expect(scheduler.scheduleFunction(function() {
93
+ }, 0)).toBe(2);
94
+ expect(scheduler.scheduleFunction(function() {
95
+ }, 0, [], false, 123)).toBe(123);
96
+ expect(scheduler.scheduleFunction(function() {
97
+ }, 0)).toBe(3);
98
+ });
99
+
100
+ it("#removeFunctionWithId removes a previously scheduled function with a given id", function() {
101
+ var scheduler = new j$.DelayedFunctionScheduler(),
102
+ fn = jasmine.createSpy('fn'),
103
+ timeoutKey;
104
+
105
+ timeoutKey = scheduler.scheduleFunction(fn, 0);
106
+
107
+ expect(fn).not.toHaveBeenCalled();
108
+
109
+ scheduler.removeFunctionWithId(timeoutKey);
110
+
111
+ scheduler.tick(0);
112
+
113
+ expect(fn).not.toHaveBeenCalled();
114
+ });
115
+
116
+ it("reset removes scheduled functions", function() {
117
+ var scheduler = new j$.DelayedFunctionScheduler(),
118
+ fn = jasmine.createSpy('fn');
119
+
120
+ scheduler.scheduleFunction(fn, 0);
121
+
122
+ expect(fn).not.toHaveBeenCalled();
123
+
124
+ scheduler.reset();
125
+
126
+ scheduler.tick(0);
127
+
128
+ expect(fn).not.toHaveBeenCalled();
129
+ });
130
+
131
+ it("reset resets the returned ids", function() {
132
+ var scheduler = new j$.DelayedFunctionScheduler();
133
+ expect(scheduler.scheduleFunction(function() { }, 0)).toBe(1);
134
+ expect(scheduler.scheduleFunction(function() { }, 0, [], false, 123)).toBe(123);
135
+
136
+ scheduler.reset();
137
+ expect(scheduler.scheduleFunction(function() { }, 0)).toBe(1);
138
+ expect(scheduler.scheduleFunction(function() { }, 0, [], false, 123)).toBe(123);
139
+ });
140
+
141
+ it("reset resets the current tick time", function() {
142
+ var scheduler = new j$.DelayedFunctionScheduler(),
143
+ fn = jasmine.createSpy('fn');
144
+
145
+ expect(fn).not.toHaveBeenCalled();
146
+
147
+ scheduler.tick(15);
148
+ scheduler.reset();
149
+
150
+ scheduler.scheduleFunction(fn, 20, [], false, 1, 20);
151
+
152
+ scheduler.tick(5);
153
+
154
+ expect(fn).not.toHaveBeenCalled();
155
+ });
156
+
157
+ it("executes recurring functions interleaved with regular functions in the correct order", function() {
158
+ var scheduler = new j$.DelayedFunctionScheduler(),
159
+ fn = jasmine.createSpy('fn'),
160
+ recurringCallCount = 0,
161
+ recurring = jasmine.createSpy('recurring').and.callFake(function() {
162
+ recurringCallCount++;
163
+ if (recurringCallCount < 5) {
164
+ expect(fn).not.toHaveBeenCalled();
165
+ }
166
+ });
167
+
168
+ scheduler.scheduleFunction(recurring, 10, [], true);
169
+ scheduler.scheduleFunction(fn, 50);
170
+
171
+ scheduler.tick(60);
172
+
173
+ expect(recurring).toHaveBeenCalled();
174
+ expect(recurring.calls.count()).toBe(6);
175
+ expect(fn).toHaveBeenCalled();
176
+ });
177
+
178
+ });
179
+
@@ -1,12 +1,13 @@
1
- describe("jasmine.Env", function() {
1
+ // TODO: Fix these unit tests!
2
+ describe("Env", function() {
2
3
  var env;
3
4
  beforeEach(function() {
4
- env = new jasmine.Env();
5
+ env = new j$.Env();
5
6
  env.updateInterval = 0;
6
7
  });
7
8
 
8
- describe('ids', function () {
9
- it('nextSpecId should return consecutive integers, starting at 0', function () {
9
+ describe('ids', function() {
10
+ it('nextSpecId should return consecutive integers, starting at 0', function() {
10
11
  expect(env.nextSpecId()).toEqual(0);
11
12
  expect(env.nextSpecId()).toEqual(1);
12
13
  expect(env.nextSpecId()).toEqual(2);
@@ -17,143 +18,494 @@ describe("jasmine.Env", function() {
17
18
  var fakeReporter;
18
19
 
19
20
  beforeEach(function() {
20
- fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]);
21
+ fakeReporter = jasmine.createSpyObj("fakeReporter", ["jasmineStarted"]);
21
22
  });
22
23
 
23
- describe('version', function () {
24
- var oldVersion;
24
+ it("should allow reporters to be registered", function() {
25
+ env.addReporter(fakeReporter);
26
+ env.reporter.jasmineStarted();
27
+ expect(fakeReporter.jasmineStarted).toHaveBeenCalled();
28
+ });
29
+ });
30
+
31
+ it('removes all spies when env is executed', function(done) {
32
+ originalFoo = function() {},
33
+ testObj = {
34
+ foo: originalFoo
35
+ },
36
+ firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
37
+ env.spyOn(testObj, 'foo');
38
+ }),
39
+ secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
40
+ expect(testObj.foo).toBe(originalFoo);
41
+ });
42
+ env.describe('test suite', function() {
43
+ env.it('spec 0', firstSpec);
44
+ env.it('spec 1', secondSpec);
45
+ });
25
46
 
26
- beforeEach(function () {
27
- oldVersion = jasmine.version_;
28
- });
47
+ var assertions = function() {
48
+ expect(firstSpec).toHaveBeenCalled();
49
+ expect(secondSpec).toHaveBeenCalled();
50
+ done();
51
+ };
29
52
 
30
- afterEach(function () {
31
- jasmine.version_ = oldVersion;
32
- });
53
+ env.addReporter({ jasmineDone: assertions });
54
+
55
+ env.execute();
56
+ });
57
+
58
+ describe("#spyOn", function() {
59
+ it("checks for the existance of the object", function() {
60
+ expect(function() {
61
+ env.spyOn(void 0, 'pants');
62
+ }).toThrowError(/could not find an object/);
63
+ });
64
+
65
+ it("checks for the existance of the method", function() {
66
+ var subject = {};
67
+
68
+ expect(function() {
69
+ env.spyOn(subject, 'pants');
70
+ }).toThrowError(/method does not exist/);
71
+ });
72
+
73
+ it("checks if it has already been spied upon", function() {
74
+ var subject = { spiedFunc: function() {} };
75
+
76
+ env.spyOn(subject, 'spiedFunc');
77
+
78
+ expect(function() {
79
+ env.spyOn(subject, 'spiedFunc');
80
+ }).toThrowError(/has already been spied upon/);
81
+ });
33
82
 
34
- it('should raise an error if version is not set', function () {
35
- jasmine.version_ = null;
36
- var exception;
37
- try {
38
- env.version();
39
- }
40
- catch (e) {
41
- exception = e;
42
- }
43
- expect(exception.message).toEqual('Version not set');
83
+ it("overrides the method on the object and returns the spy", function() {
84
+ var originalFunctionWasCalled = false;
85
+ var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
86
+
87
+ originalFunc = subject.spiedFunc;
88
+
89
+ var spy = env.spyOn(subject, 'spiedFunc');
90
+
91
+ expect(subject.spiedFunc).toEqual(spy);
92
+
93
+ expect(subject.spiedFunc.calls.any()).toEqual(false);
94
+ expect(subject.spiedFunc.calls.count()).toEqual(0);
95
+
96
+ subject.spiedFunc('foo');
97
+
98
+ expect(subject.spiedFunc.calls.any()).toEqual(true);
99
+ expect(subject.spiedFunc.calls.count()).toEqual(1);
100
+ expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
101
+ expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
102
+ expect(originalFunctionWasCalled).toEqual(false);
103
+
104
+ subject.spiedFunc('bar');
105
+ expect(subject.spiedFunc.calls.count()).toEqual(2);
106
+ expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
107
+ });
108
+ });
109
+
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
+ describe("#pending", function() {
126
+ it("throws the Pending Spec exception", function() {
127
+ expect(function() {
128
+ env.pending();
129
+ }).toThrow(j$.Spec.pendingSpecExceptionMessage);
130
+ });
131
+ });
132
+
133
+ });
134
+
135
+ // TODO: move these into a separate file
136
+ describe("Env integration", function() {
137
+
138
+ it("Suites execute as expected (no nesting)", function(done) {
139
+ var env = new j$.Env(),
140
+ calls = [];
141
+
142
+ var assertions = function() {
143
+ expect(calls).toEqual([
144
+ "with a spec",
145
+ "and another spec"
146
+ ]);
147
+
148
+ done();
149
+ };
150
+
151
+ env.addReporter({ jasmineDone: assertions});
152
+
153
+ env.describe("A Suite", function() {
154
+ env.it("with a spec", function() {
155
+ calls.push("with a spec");
156
+ });
157
+ env.it("and another spec", function() {
158
+ calls.push("and another spec");
44
159
  });
160
+ });
161
+
162
+ env.execute();
163
+ });
45
164
 
46
- it("version should return the current version as an int", function() {
47
- jasmine.version_ = {
48
- "major": 1,
49
- "minor": 9,
50
- "build": 7,
51
- "revision": 8
52
- };
53
- expect(env.version()).toEqual({
54
- "major": 1,
55
- "minor": 9,
56
- "build": 7,
57
- "revision": 8
165
+ it("Nested Suites execute as expected", function(done) {
166
+ var env = new j$.Env(),
167
+ calls = [];
168
+
169
+ var assertions = function() {
170
+ expect(calls).toEqual([
171
+ 'an outer spec',
172
+ 'an inner spec',
173
+ 'another inner spec'
174
+ ]);
175
+
176
+ done();
177
+ };
178
+
179
+ env.addReporter({ jasmineDone: assertions });
180
+
181
+ env.describe("Outer suite", function() {
182
+ env.it("an outer spec", function() {
183
+ calls.push('an outer spec')
184
+ });
185
+ env.describe("Inner suite", function() {
186
+ env.it("an inner spec", function() {
187
+ calls.push('an inner spec');
188
+ });
189
+ env.it("another inner spec", function() {
190
+ calls.push('another inner spec');
58
191
  });
59
192
  });
193
+ });
60
194
 
61
- describe("versionString", function() {
62
- it("should return a stringified version number", function() {
63
- jasmine.version_ = {
64
- "major": 1,
65
- "minor": 9,
66
- "build": 7,
67
- "release_candidate": "1",
68
- "revision": 8
69
- };
70
- expect(env.versionString()).toEqual("1.9.7.rc1 revision 8");
71
- });
195
+ env.execute();
196
+ });
72
197
 
73
- it("should return a nice string when version is unknown", function() {
74
- jasmine.version_ = null;
75
- expect(env.versionString()).toEqual("version unknown");
198
+ it("Multiple top-level Suites execute as expected", function(done) {
199
+ var env = new j$.Env(),
200
+ calls = [];
201
+
202
+ var assertions = function() {
203
+ expect(calls).toEqual([
204
+ 'an outer spec',
205
+ 'an inner spec',
206
+ 'another inner spec',
207
+ 'a 2nd outer spec'
208
+ ]);
209
+
210
+ done();
211
+ };
212
+
213
+ env.addReporter({ jasmineDone: assertions });
214
+
215
+
216
+ env.describe("Outer suite", function() {
217
+ env.it("an outer spec", function() {
218
+ calls.push('an outer spec')
219
+ });
220
+ env.describe("Inner suite", function() {
221
+ env.it("an inner spec", function() {
222
+ calls.push('an inner spec');
223
+ });
224
+ env.it("another inner spec", function() {
225
+ calls.push('another inner spec');
76
226
  });
77
227
  });
78
228
  });
79
229
 
80
- it("should allow reporters to be registered", function() {
81
- env.addReporter(fakeReporter);
82
- env.reporter.log("message");
83
- expect(fakeReporter.log).toHaveBeenCalledWith("message");
230
+ env.describe("Another outer suite", function() {
231
+ env.it("a 2nd outer spec", function() {
232
+ calls.push('a 2nd outer spec')
233
+ });
84
234
  });
235
+
236
+ env.execute();
85
237
  });
86
238
 
87
- describe("equality testing", function() {
88
- describe("with custom equality testers", function() {
89
- var aObj, bObj, isEqual;
239
+ it("Mock clock can be installed and used in tests", function(done) {
240
+ var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
241
+ delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
242
+ delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'),
243
+ env = new j$.Env({global: { setTimeout: globalSetTimeout }});
90
244
 
91
- beforeEach(function() {
92
- env.addEqualityTester(function(a, b) {
93
- aObj = a;
94
- bObj = b;
95
- return isEqual;
96
- });
245
+ var assertions = function() {
246
+ expect(delayedFunctionForMockClock).toHaveBeenCalled();
247
+ expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100);
248
+
249
+ done();
250
+ };
251
+
252
+ env.addReporter({ jasmineDone: assertions });
253
+
254
+ env.describe("tests", function() {
255
+ env.it("test with mock clock", function() {
256
+ env.clock.install();
257
+ env.clock.setTimeout(delayedFunctionForMockClock, 100);
258
+ env.clock.tick(100);
259
+ });
260
+ env.it("test without mock clock", function() {
261
+ env.clock.setTimeout(delayedFunctionForGlobalClock, 100);
262
+ });
263
+ });
264
+
265
+ expect(globalSetTimeout).not.toHaveBeenCalled();
266
+ expect(delayedFunctionForMockClock).not.toHaveBeenCalled();
267
+
268
+ env.execute();
269
+ });
270
+
271
+ it("should run async specs in order, waiting for them to complete", function(done) {
272
+ var env = new j$.Env(), mutatedVar;
273
+
274
+ env.describe("tests", function() {
275
+ env.beforeEach(function() {
276
+ mutatedVar = 2;
97
277
  });
98
278
 
99
- it("should call the custom equality tester with two objects for comparison", function() {
100
- env.equals_("1", "2");
101
- expect(aObj).toEqual("1");
102
- expect(bObj).toEqual("2");
279
+ env.it("async spec", function(underTestCallback) {
280
+ setTimeout(function() {
281
+ expect(mutatedVar).toEqual(2);
282
+ underTestCallback();
283
+ done();
284
+ }, 0);
103
285
  });
104
286
 
105
- describe("when the custom equality tester returns false", function() {
106
- beforeEach(function() {
107
- isEqual = false;
108
- });
287
+ env.it("after async spec", function() {
288
+ mutatedVar = 3;
289
+ });
290
+ });
109
291
 
110
- it("should give custom equality testers precedence", function() {
111
- expect(env.equals_('abc', 'abc')).toBeFalsy();
112
- var o = {};
113
- expect(env.equals_(o, o)).toBeFalsy();
114
- });
292
+ env.execute();
293
+ });
294
+
295
+ describe("with a mock clock", function() {
296
+ beforeEach(function() {
297
+ jasmine.getEnv().clock.install();
115
298
  });
116
299
 
300
+ afterEach(function() {
301
+ jasmine.getEnv().clock.uninstall();
302
+ });
117
303
 
118
- describe("when the custom equality tester returns true", function() {
119
- beforeEach(function() {
120
- isEqual = true;
121
- });
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
+ ]);
122
314
 
123
- it("should give custom equality testers precedence", function() {
124
- expect(env.equals_('abc', 'def')).toBeTruthy();
125
- expect(env.equals_(true, false)).toBeTruthy();
126
- });
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
+ });
321
+
322
+ env.it("after async spec", function() {
323
+ env.expect(true).toBeTruthy();
324
+ });
325
+ });
326
+
327
+ env.execute();
328
+
329
+ reporter.jasmineDone.and.callFake(function() {
330
+ expect(reporter.jasmineStarted).toHaveBeenCalledWith({
331
+ totalSpecsDefined: 2
332
+ });
333
+
334
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'passed'}));
335
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
336
+
337
+ done();
338
+ });
339
+
340
+ jasmine.getEnv().clock.tick(60001);
127
341
  });
342
+ });
128
343
 
129
- describe("when the custom equality tester returns undefined", function() {
130
- beforeEach(function() {
131
- isEqual = jasmine.undefined;
132
- });
344
+ // TODO: something is wrong with this spec
345
+ it("should report as expected", function(done) {
346
+ var env = new j$.Env(),
347
+ reporter = jasmine.createSpyObj('fakeReporter', [
348
+ "jasmineStarted",
349
+ "jasmineDone",
350
+ "suiteStarted",
351
+ "suiteDone",
352
+ "specStarted",
353
+ "specDone"
354
+ ]);
355
+
356
+ reporter.jasmineDone.and.callFake(function() {
357
+ expect(reporter.jasmineStarted).toHaveBeenCalledWith({
358
+ totalSpecsDefined: 3
359
+ });
360
+ var suiteResult = reporter.suiteStarted.calls.first().args[0];
361
+ expect(suiteResult.description).toEqual("A Suite");
362
+ expect(reporter.jasmineDone).toHaveBeenCalled();
133
363
 
134
- it("should use normal equality rules", function() {
135
- expect(env.equals_('abc', 'abc')).toBeTruthy();
136
- expect(env.equals_('abc', 'def')).toBeFalsy();
364
+ done();
365
+ });
366
+
367
+ env.addReporter(reporter);
368
+
369
+ env.describe("A Suite", function() {
370
+ env.it("with a top level spec", function() {
371
+ env.expect(true).toBe(true);
372
+ });
373
+ env.describe("with a nested suite", function() {
374
+ env.xit("with a pending spec", function() {
375
+ env.expect(true).toBe(true);
376
+ });
377
+ env.it("with a spec", function() {
378
+ env.expect(true).toBe(false);
137
379
  });
380
+ });
381
+ });
138
382
 
139
- describe("even if there are several", function() {
140
- beforeEach(function() {
141
- env.addEqualityTester(function(a, b) { return jasmine.undefined; });
142
- env.addEqualityTester(function(a, b) { return jasmine.undefined; });
143
- });
383
+ env.execute();
384
+ });
144
385
 
145
- it("should use normal equality rules", function() {
146
- expect(env.equals_('abc', 'abc')).toBeTruthy();
147
- expect(env.equals_('abc', 'def')).toBeFalsy();
386
+ it("should be possible to get full name from a spec", function() {
387
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
388
+ topLevelSpec, nestedSpec, doublyNestedSpec;
389
+
390
+ env.describe("my tests", function() {
391
+ topLevelSpec = env.it("are sometimes top level", function() {
392
+ });
393
+ env.describe("are sometimes", function() {
394
+ nestedSpec = env.it("singly nested", function() {
395
+ });
396
+ env.describe("even", function() {
397
+ doublyNestedSpec = env.it("doubly nested", function() {
148
398
  });
149
399
  });
150
400
  });
401
+ });
402
+
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.");
406
+ });
407
+
408
+ it("Custom equality testers should be per spec", function(done) {
409
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
410
+ reporter = jasmine.createSpyObj('fakeReproter', [
411
+ "jasmineStarted",
412
+ "jasmineDone",
413
+ "suiteStarted",
414
+ "suiteDone",
415
+ "specStarted",
416
+ "specDone"
417
+ ]);
418
+
419
+ reporter.jasmineDone.and.callFake(function() {
420
+ var firstSpecResult = reporter.specDone.calls.first().args[0],
421
+ secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
151
422
 
152
- it("should evaluate custom equality testers in the order they are declared", function() {
153
- isEqual = false;
154
- env.addEqualityTester(function(a, b) { return true; });
155
- expect(env.equals_('abc', 'abc')).toBeFalsy();
423
+ expect(firstSpecResult.status).toEqual("passed");
424
+ expect(secondSpecResult.status).toEqual("failed");
425
+
426
+ done();
427
+ });
428
+
429
+ env.addReporter(reporter);
430
+
431
+ env.describe("testing custom equality testers", function() {
432
+ env.it("with a custom tester", function() {
433
+ env.addCustomEqualityTester(function(a, b) { return true; });
434
+ env.expect("a").toEqual("b");
435
+ });
436
+
437
+ env.it("without a custom tester", function() {
438
+ env.expect("a").toEqual("b");
156
439
  });
157
440
  });
441
+
442
+ env.execute();
443
+ });
444
+
445
+ it("Custom matchers should be per spec", function() {
446
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
447
+ matchers = {
448
+ toFoo: function() {}
449
+ },
450
+ reporter = jasmine.createSpyObj('fakeReproter', [
451
+ "jasmineStarted",
452
+ "jasmineDone",
453
+ "suiteStarted",
454
+ "suiteDone",
455
+ "specStarted",
456
+ "specDone"
457
+ ]);
458
+
459
+ env.addReporter(reporter);
460
+
461
+ env.describe("testing custom matchers", function() {
462
+ env.it("with a custom matcher", function() {
463
+ env.addMatchers(matchers);
464
+ expect(env.expect().toFoo).toBeDefined();
465
+ });
466
+
467
+ env.it("without a custom matcher", function() {
468
+ expect(env.expect().toFoo).toBeUndefined();
469
+ });
470
+ });
471
+
472
+ env.execute();
473
+ });
474
+
475
+ it("Custom equality testers for toContain should be per spec", function(done) {
476
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
477
+ reporter = jasmine.createSpyObj('fakeReproter', [
478
+ "jasmineStarted",
479
+ "jasmineDone",
480
+ "suiteStarted",
481
+ "suiteDone",
482
+ "specStarted",
483
+ "specDone"
484
+ ]);
485
+
486
+ reporter.jasmineDone.and.callFake(function() {
487
+ var firstSpecResult = reporter.specDone.calls.first().args[0],
488
+ secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
489
+
490
+ expect(firstSpecResult.status).toEqual("passed");
491
+ expect(secondSpecResult.status).toEqual("failed");
492
+
493
+ done();
494
+ });
495
+
496
+ env.addReporter(reporter);
497
+
498
+ env.describe("testing custom equality testers", function() {
499
+ env.it("with a custom tester", function() {
500
+ env.addCustomEqualityTester(function(a, b) { return true; });
501
+ env.expect(["a"]).toContain("b");
502
+ });
503
+
504
+ env.it("without a custom tester", function() {
505
+ env.expect("a").toContain("b");
506
+ });
507
+ });
508
+
509
+ env.execute();
158
510
  });
159
511
  });