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,124 +1,244 @@
1
- describe('Spec', function () {
2
- var env, suite;
3
- beforeEach(function() {
4
- env = new jasmine.Env();
5
- env.updateInterval = 0;
6
- suite = new jasmine.Suite(env, 'suite 1');
7
- });
1
+ describe("Spec", function() {
8
2
 
9
- describe('initialization', function () {
3
+ it("#isPendingSpecException returns true for a pending spec exception", function() {
4
+ var e = new Error(j$.Spec.pendingSpecExceptionMessage);
10
5
 
11
- it('should raise an error if an env is not passed', function () {
12
- try {
13
- new jasmine.Spec();
14
- }
15
- catch (e) {
16
- expect(e.message).toEqual('jasmine.Env() required');
17
- }
18
- });
6
+ expect(j$.Spec.isPendingSpecException(e)).toBe(true);
7
+ });
19
8
 
20
- it('should raise an error if a suite is not passed', function () {
21
- try {
22
- new jasmine.Spec(env);
23
- }
24
- catch (e) {
25
- expect(e.message).toEqual('jasmine.Suite() required');
26
- }
27
- });
9
+ it("#isPendingSpecException returns true for a pending spec exception (even when FF bug is present)", function() {
10
+ var fakeError = {
11
+ toString: function() { return "Error: " + j$.Spec.pendingSpecExceptionMessage; }
12
+ };
28
13
 
29
- it('should assign sequential ids for specs belonging to the same env', function () {
30
- var spec1 = new jasmine.Spec(env, suite);
31
- var spec2 = new jasmine.Spec(env, suite);
32
- var spec3 = new jasmine.Spec(env, suite);
33
- expect(spec1.id).toEqual(0);
34
- expect(spec2.id).toEqual(1);
35
- expect(spec3.id).toEqual(2);
36
- });
14
+ expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
37
15
  });
38
16
 
39
- it('getFullName returns suite & spec description', function () {
40
- var spec = new jasmine.Spec(env, suite, 'spec 1');
41
- expect(spec.getFullName()).toEqual('suite 1 spec 1.');
17
+ it("#isPendingSpecException returns true for a pending spec exception", function() {
18
+ var e = new Error("foo");
19
+
20
+ expect(j$.Spec.isPendingSpecException(e)).toBe(false);
42
21
  });
43
22
 
44
- describe('results', function () {
45
- var spec, results;
46
- beforeEach(function () {
47
- spec = new jasmine.Spec(env, suite);
48
- results = spec.results();
49
- expect(results.totalCount).toEqual(0);
50
- spec.runs(function () {
51
- this.expect(true).toEqual(true);
52
- this.expect(true).toEqual(true);
23
+ it("delegates execution to a QueueRunner", function() {
24
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
25
+ spec = new j$.Spec({
26
+ description: 'my test',
27
+ id: 'some-id',
28
+ fn: function() {},
29
+ queueRunner: fakeQueueRunner
53
30
  });
54
- });
55
31
 
32
+ spec.execute();
56
33
 
57
- it('results shows the total number of expectations for each spec after execution', function () {
58
- expect(results.totalCount).toEqual(0);
59
- spec.execute();
60
- expect(results.totalCount).toEqual(2);
61
- });
34
+ expect(fakeQueueRunner).toHaveBeenCalled();
35
+ });
62
36
 
63
- it('results shows the number of passed expectations for each spec after execution', function () {
64
- expect(results.passedCount).toEqual(0);
65
- spec.execute();
66
- expect(results.passedCount).toEqual(2);
67
- });
37
+ it("should call the start callback on execution", function() {
38
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
39
+ beforesWereCalled = false,
40
+ startCallback = jasmine.createSpy('startCallback'),
41
+ spec = new j$.Spec({
42
+ id: 123,
43
+ description: 'foo bar',
44
+ fn: function() {},
45
+ onStart: startCallback,
46
+ queueRunner: fakeQueueRunner
47
+ });
68
48
 
69
- it('results shows the number of failed expectations for each spec after execution', function () {
70
- spec.runs(function () {
71
- this.expect(true).toEqual(false);
49
+ spec.execute();
50
+
51
+ expect(startCallback).toHaveBeenCalledWith(spec);
52
+ });
53
+
54
+ it("should call the start callback on execution but before any befores are called", function() {
55
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
56
+ beforesWereCalled = false,
57
+ startCallback = jasmine.createSpy('start-callback').and.callFake(function() {
58
+ expect(beforesWereCalled).toBe(false);
59
+ }),
60
+ spec = new j$.Spec({
61
+ fn: function() {},
62
+ beforeFns: function() {
63
+ return [function() {
64
+ beforesWereCalled = true
65
+ }]
66
+ },
67
+ onStart: startCallback,
68
+ queueRunner: fakeQueueRunner
72
69
  });
73
- expect(results.failedCount).toEqual(0);
74
- spec.execute();
75
- expect(results.failedCount).toEqual(1);
76
- });
77
70
 
78
- describe('results.passed', function () {
79
- it('is true if all spec expectations pass', function () {
80
- spec.runs(function () {
81
- this.expect(true).toEqual(true);
82
- });
83
- spec.execute();
84
- expect(results.passed()).toEqual(true);
71
+ spec.execute();
72
+
73
+ expect(startCallback).toHaveBeenCalled();
74
+ });
75
+
76
+ it("provides all before fns and after fns to be run", function() {
77
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
78
+ before = jasmine.createSpy('before'),
79
+ after = jasmine.createSpy('after'),
80
+ fn = jasmine.createSpy('test body').and.callFake(function() {
81
+ expect(before).toHaveBeenCalled();
82
+ expect(after).not.toHaveBeenCalled();
83
+ }),
84
+ spec = new j$.Spec({
85
+ fn: fn,
86
+ beforeFns: function() {
87
+ return [before]
88
+ },
89
+ afterFns: function() {
90
+ return [after]
91
+ },
92
+ queueRunner: fakeQueueRunner
85
93
  });
86
94
 
87
- it('is false if one spec expectation fails', function () {
88
- spec.runs(function () {
89
- this.expect(true).toEqual(false);
90
- });
91
- spec.execute();
92
- expect(results.passed()).toEqual(false);
95
+ spec.execute();
96
+
97
+ var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].fns;
98
+ expect(allSpecFns).toEqual([before, fn, after]);
99
+ });
100
+
101
+ it("is marked pending if created without a function body", function() {
102
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
103
+
104
+ startCallback = jasmine.createSpy('startCallback'),
105
+ resultCallback = jasmine.createSpy('resultCallback'),
106
+ spec = new j$.Spec({
107
+ onStart: startCallback,
108
+ fn: null,
109
+ resultCallback: resultCallback,
110
+ queueRunner: fakeQueueRunner
93
111
  });
94
112
 
95
- it('a spec with no expectations will return true', function () {
96
- var specWithoutExpectations = new jasmine.Spec(env, suite);
97
- specWithoutExpectations.runs(function() {
98
113
 
99
- });
100
- specWithoutExpectations.execute();
101
- expect(results.passed()).toEqual(true);
114
+ expect(spec.status()).toBe('pending');
115
+ });
116
+
117
+ it("can be disabled, but still calls callbacks", function() {
118
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
119
+ startCallback = jasmine.createSpy('startCallback'),
120
+ specBody = jasmine.createSpy('specBody'),
121
+ resultCallback = jasmine.createSpy('resultCallback'),
122
+ spec = new j$.Spec({
123
+ onStart:startCallback,
124
+ fn: specBody,
125
+ resultCallback: resultCallback,
126
+ queueRunner: fakeQueueRunner
102
127
  });
103
128
 
104
- it('an unexecuted spec will return true', function () {
105
- expect(results.passed()).toEqual(true);
129
+ spec.disable();
130
+
131
+ expect(spec.status()).toBe('disabled');
132
+
133
+ spec.execute();
134
+
135
+ expect(fakeQueueRunner).not.toHaveBeenCalled();
136
+ expect(specBody).not.toHaveBeenCalled();
137
+
138
+ expect(startCallback).toHaveBeenCalled();
139
+ expect(resultCallback).toHaveBeenCalled();
140
+ });
141
+
142
+ it("can be marked pending, but still calls callbacks when executed", function() {
143
+ var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
144
+ startCallback = jasmine.createSpy('startCallback'),
145
+ resultCallback = jasmine.createSpy('resultCallback'),
146
+ spec = new j$.Spec({
147
+ onStart: startCallback,
148
+ resultCallback: resultCallback,
149
+ description: "with a spec",
150
+ getSpecName: function() {
151
+ return "a suite with a spec"
152
+ },
153
+ queueRunner: fakeQueueRunner
106
154
  });
155
+
156
+ spec.pend();
157
+
158
+ expect(spec.status()).toBe('pending');
159
+
160
+ spec.execute();
161
+
162
+ expect(fakeQueueRunner).not.toHaveBeenCalled();
163
+
164
+ expect(startCallback).toHaveBeenCalled();
165
+ expect(resultCallback).toHaveBeenCalledWith({
166
+ id: spec.id,
167
+ status: 'pending',
168
+ description: 'with a spec',
169
+ fullName: 'a suite with a spec',
170
+ failedExpectations: []
107
171
  });
172
+ });
108
173
 
109
- it("includes log messages, which may contain arbitary objects", function() {
110
- spec.runs(function() {
111
- this.log("here's some log message", {key: 'value'}, 123);
174
+ it("should call the done callback on execution complete", function() {
175
+ var done = jasmine.createSpy('done callback'),
176
+ spec = new j$.Spec({
177
+ fn: function() {},
178
+ catchExceptions: function() { return false; },
179
+ resultCallback: function() {},
180
+ queueRunner: function(attrs) { attrs.onComplete(); }
112
181
  });
182
+
183
+ spec.execute(done);
184
+
185
+ expect(done).toHaveBeenCalled();
186
+ });
187
+
188
+ it("#status returns pending by default", function() {
189
+ var spec = new j$.Spec({fn: jasmine.createSpy("spec body")});
190
+ expect(spec.status()).toEqual('pending');
191
+ });
192
+
193
+ it("#status returns pending if no expectations were encountered", function() {
194
+ var specBody = jasmine.createSpy("spec body"),
195
+ spec = new j$.Spec({fn: specBody});
196
+
197
+ spec.execute();
198
+
199
+ expect(spec.status()).toEqual('pending');
200
+ });
201
+
202
+ it("#status returns passed if all expectations in the spec have passed", function() {
203
+ var spec = new j$.Spec({fn: jasmine.createSpy("spec body")});
204
+ spec.addExpectationResult(true);
205
+ expect(spec.status()).toBe('passed');
206
+ });
207
+
208
+ it("#status returns failed if any expectations in the spec have failed", function() {
209
+ var spec = new j$.Spec({ fn: jasmine.createSpy("spec body") });
210
+ spec.addExpectationResult(true);
211
+ spec.addExpectationResult(false);
212
+ expect(spec.status()).toBe('failed');
213
+ });
214
+
215
+ it("can return its full name", function() {
216
+ var spec;
217
+ spec = new j$.Spec({
218
+ getSpecName: function(passedVal) {
219
+ // expect(passedVal).toBe(spec); TODO: a exec time, spec is undefined WTF?
220
+ return 'expected val';
221
+ }
222
+ });
223
+
224
+ expect(spec.getFullName()).toBe('expected val');
225
+ });
226
+
227
+ describe("when a spec is marked pending during execution", function() {
228
+ it("should mark the spec as pending", function() {
229
+ var fakeQueueRunner = function(opts) {
230
+ opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage));
231
+ },
232
+ spec = new j$.Spec({
233
+ description: 'my test',
234
+ id: 'some-id',
235
+ fn: function() { },
236
+ queueRunner: fakeQueueRunner
237
+ });
238
+
113
239
  spec.execute();
114
- var items = results.getItems();
115
- expect(items).toEqual([
116
- jasmine.any(jasmine.ExpectationResult),
117
- jasmine.any(jasmine.ExpectationResult),
118
- jasmine.any(jasmine.MessageResult)
119
- ]);
120
- var logResult = items[2];
121
- expect(logResult.values).toEqual(["here's some log message", {key: 'value'}, 123]);
240
+
241
+ expect(spec.status()).toEqual("pending");
122
242
  });
123
243
  });
124
- });
244
+ });
@@ -1,216 +1,48 @@
1
1
  describe('Spies', function () {
2
- it('should replace the specified function with a spy object', function() {
3
- var originalFunctionWasCalled = false;
4
- var TestClass = {
5
- someFunction: function() {
6
- originalFunctionWasCalled = true;
7
- }
8
- };
9
- this.spyOn(TestClass, 'someFunction');
2
+ describe("createSpy", function() {
3
+ var TestClass;
10
4
 
11
- expect(TestClass.someFunction.wasCalled).toEqual(false);
12
- expect(TestClass.someFunction.callCount).toEqual(0);
13
- TestClass.someFunction('foo');
14
- expect(TestClass.someFunction.wasCalled).toEqual(true);
15
- expect(TestClass.someFunction.callCount).toEqual(1);
16
- expect(TestClass.someFunction.mostRecentCall.args).toEqual(['foo']);
17
- expect(TestClass.someFunction.mostRecentCall.object).toEqual(TestClass);
18
- expect(originalFunctionWasCalled).toEqual(false);
19
-
20
- TestClass.someFunction('bar');
21
- expect(TestClass.someFunction.callCount).toEqual(2);
22
- expect(TestClass.someFunction.mostRecentCall.args).toEqual(['bar']);
23
- });
24
-
25
- it('should allow you to view args for a particular call', function() {
26
- var originalFunctionWasCalled = false;
27
- var TestClass = {
28
- someFunction: function() {
29
- originalFunctionWasCalled = true;
30
- }
31
- };
32
- this.spyOn(TestClass, 'someFunction');
33
-
34
- TestClass.someFunction('foo');
35
- TestClass.someFunction('bar');
36
- expect(TestClass.someFunction.calls[0].args).toEqual(['foo']);
37
- expect(TestClass.someFunction.calls[1].args).toEqual(['bar']);
38
- expect(TestClass.someFunction.mostRecentCall.args).toEqual(['bar']);
39
- });
40
-
41
- it('should be possible to call through to the original method, or return a specific result', function() {
42
- var originalFunctionWasCalled = false;
43
- var passedArgs;
44
- var passedObj;
45
- var TestClass = {
46
- someFunction: function() {
47
- originalFunctionWasCalled = true;
48
- passedArgs = arguments;
49
- passedObj = this;
50
- return "return value from original function";
51
- }
52
- };
53
-
54
- this.spyOn(TestClass, 'someFunction').andCallThrough();
55
- var result = TestClass.someFunction('arg1', 'arg2');
56
- expect(result).toEqual("return value from original function");
57
- expect(originalFunctionWasCalled).toEqual(true);
58
- expect(passedArgs).toEqual(['arg1', 'arg2']);
59
- expect(passedObj).toEqual(TestClass);
60
- expect(TestClass.someFunction.wasCalled).toEqual(true);
61
- });
62
-
63
- it('should be possible to return a specific value', function() {
64
- var originalFunctionWasCalled = false;
65
- var TestClass = {
66
- someFunction: function() {
67
- originalFunctionWasCalled = true;
68
- return "return value from original function";
69
- }
70
- };
71
-
72
- this.spyOn(TestClass, 'someFunction').andReturn("some value");
73
- originalFunctionWasCalled = false;
74
- var result = TestClass.someFunction('arg1', 'arg2');
75
- expect(result).toEqual("some value");
76
- expect(originalFunctionWasCalled).toEqual(false);
77
- });
78
-
79
- it('should be possible to throw a specific error', function() {
80
- var originalFunctionWasCalled = false;
81
- var TestClass = {
82
- someFunction: function() {
83
- originalFunctionWasCalled = true;
84
- return "return value from original function";
85
- }
86
- };
87
-
88
- this.spyOn(TestClass, 'someFunction').andThrow(new Error('fake error'));
89
- var exception;
90
- try {
91
- TestClass.someFunction('arg1', 'arg2');
92
- } catch (e) {
93
- exception = e;
94
- }
95
- expect(exception.message).toEqual('fake error');
96
- expect(originalFunctionWasCalled).toEqual(false);
97
- });
98
-
99
- it('should be possible to call a specified function', function() {
100
- var originalFunctionWasCalled = false;
101
- var fakeFunctionWasCalled = false;
102
- var passedArgs;
103
- var passedObj;
104
- var TestClass = {
105
- someFunction: function() {
106
- originalFunctionWasCalled = true;
107
- return "return value from original function";
108
- }
109
- };
110
-
111
- this.spyOn(TestClass, 'someFunction').andCallFake(function() {
112
- fakeFunctionWasCalled = true;
113
- passedArgs = arguments;
114
- passedObj = this;
115
- return "return value from fake function";
5
+ beforeEach(function() {
6
+ TestClass = function() {};
7
+ TestClass.prototype.someFunction = function() {};
8
+ TestClass.prototype.someFunction.bob = "test";
116
9
  });
10
+
11
+ it("preserves the properties of the spied function", function() {
12
+ var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
117
13
 
118
- var result = TestClass.someFunction('arg1', 'arg2');
119
- expect(result).toEqual("return value from fake function");
120
- expect(originalFunctionWasCalled).toEqual(false);
121
- expect(fakeFunctionWasCalled).toEqual(true);
122
- expect(passedArgs).toEqual(['arg1', 'arg2']);
123
- expect(passedObj).toEqual(TestClass);
124
- expect(TestClass.someFunction.wasCalled).toEqual(true);
125
- });
126
-
127
- it('is torn down when this.removeAllSpies is called', function() {
128
- var originalFunctionWasCalled = false;
129
- var TestClass = {
130
- someFunction: function() {
131
- originalFunctionWasCalled = true;
132
- }
133
- };
134
- this.spyOn(TestClass, 'someFunction');
135
-
136
- TestClass.someFunction('foo');
137
- expect(originalFunctionWasCalled).toEqual(false);
138
-
139
- this.removeAllSpies();
140
-
141
- TestClass.someFunction('foo');
142
- expect(originalFunctionWasCalled).toEqual(true);
143
- });
144
-
145
- it('calls removeAllSpies during spec finish', function() {
146
- var test = new jasmine.Spec(new jasmine.Env(), {}, 'sample test');
147
-
148
- this.spyOn(test, 'removeAllSpies');
149
-
150
- test.finish();
151
-
152
- expect(test.removeAllSpies).wasCalled();
153
- });
14
+ expect(spy.bob).toEqual("test");
15
+ });
154
16
 
155
- it('throws an exception when some method is spied on twice', function() {
156
- var TestClass = { someFunction: function() {
157
- } };
158
- this.spyOn(TestClass, 'someFunction');
159
- var exception;
160
- try {
161
- this.spyOn(TestClass, 'someFunction');
162
- } catch (e) {
163
- exception = e;
164
- }
165
- expect(exception).toBeDefined();
166
- });
17
+ it("warns the user that we indend to overwrite an existing property", function() {
18
+ TestClass.prototype.someFunction.and = "turkey";
167
19
 
168
-
169
- it('to spy on an undefined method throws exception', function() {
170
- var TestClass = {
171
- someFunction : function() {
172
- }
173
- };
174
- function efunc() {
175
- this.spyOn(TestClass, 'someOtherFunction');
176
- };
177
- expect(function() {
178
- efunc();
179
- }).toThrow('someOtherFunction() method does not exist');
180
-
181
- });
20
+ expect(function() {
21
+ j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
22
+ }).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
23
+ });
182
24
 
183
- it('should be able to reset a spy', function() {
184
- var TestClass = { someFunction: function() {} };
185
- this.spyOn(TestClass, 'someFunction');
25
+ it("adds a spyStrategy and callTracker to the spy", function() {
26
+ var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
186
27
 
187
- expect(TestClass.someFunction).not.toHaveBeenCalled();
188
- TestClass.someFunction();
189
- expect(TestClass.someFunction).toHaveBeenCalled();
190
- TestClass.someFunction.reset();
191
- expect(TestClass.someFunction).not.toHaveBeenCalled();
192
- expect(TestClass.someFunction.callCount).toEqual(0);
28
+ expect(spy.and).toEqual(jasmine.any(j$.SpyStrategy));
29
+ expect(spy.calls).toEqual(jasmine.any(j$.CallTracker));
30
+ });
193
31
  });
194
32
 
195
33
  describe("createSpyObj", function() {
196
34
  it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() {
197
- var spyObj = jasmine.createSpyObj('BaseName', ['method1', 'method2']);
35
+ var spyObj = j$.createSpyObj('BaseName', ['method1', 'method2']);
36
+
198
37
  expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
199
- expect(spyObj.method1.identity).toEqual('BaseName.method1');
200
- expect(spyObj.method2.identity).toEqual('BaseName.method2');
38
+ expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
39
+ expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
201
40
  });
202
41
 
203
42
  it("should throw if you do not pass an array argument", function() {
204
43
  expect(function() {
205
- jasmine.createSpyObj('BaseName');
206
- }).toThrow('createSpyObj requires a non-empty array of method names to create spies for');
207
- });
208
-
209
- it("should throw if you pass an empty array argument", function() {
210
- expect(function() {
211
- jasmine.createSpyObj('BaseName');
212
- }).toThrow('createSpyObj requires a non-empty array of method names to create spies for');
44
+ j$.createSpyObj('BaseName');
45
+ }).toThrow("createSpyObj requires a non-empty array of method names to create spies for");
213
46
  });
214
47
  });
215
-
216
48
  });