jasmine-core 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jasmine-core/boot/node_boot.js +1 -1
  3. data/lib/jasmine-core/jasmine-html.js +0 -35
  4. data/lib/jasmine-core/jasmine.css +0 -6
  5. data/lib/jasmine-core/jasmine.js +246 -36
  6. data/lib/jasmine-core/node_boot.js +1 -1
  7. data/lib/jasmine-core/version.rb +1 -1
  8. metadata +3 -88
  9. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +0 -130
  10. data/lib/jasmine-core/spec/core/ClearStackSpec.js +0 -137
  11. data/lib/jasmine-core/spec/core/ClockSpec.js +0 -710
  12. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +0 -286
  13. data/lib/jasmine-core/spec/core/EnvSpec.js +0 -200
  14. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +0 -120
  15. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +0 -46
  16. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +0 -61
  17. data/lib/jasmine-core/spec/core/ExpectationSpec.js +0 -434
  18. data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +0 -110
  19. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +0 -259
  20. data/lib/jasmine-core/spec/core/MockDateSpec.js +0 -200
  21. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +0 -332
  22. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +0 -670
  23. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +0 -140
  24. data/lib/jasmine-core/spec/core/SpecSpec.js +0 -407
  25. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +0 -364
  26. data/lib/jasmine-core/spec/core/SpySpec.js +0 -177
  27. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +0 -202
  28. data/lib/jasmine-core/spec/core/StackTraceSpec.js +0 -166
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +0 -123
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +0 -31
  31. data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +0 -794
  32. data/lib/jasmine-core/spec/core/UserContextSpec.js +0 -54
  33. data/lib/jasmine-core/spec/core/UtilSpec.js +0 -105
  34. data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +0 -91
  35. data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +0 -76
  36. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +0 -52
  37. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +0 -47
  38. data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +0 -99
  39. data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +0 -27
  40. data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +0 -13
  41. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +0 -200
  42. data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +0 -138
  43. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +0 -2344
  44. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +0 -976
  45. data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +0 -47
  46. data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +0 -13
  47. data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +0 -43
  48. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +0 -645
  49. data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +0 -8
  50. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +0 -93
  51. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +0 -18
  52. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +0 -38
  53. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +0 -29
  54. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +0 -20
  55. data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +0 -29
  56. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +0 -20
  57. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +0 -37
  58. data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +0 -31
  59. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +0 -17
  60. data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +0 -31
  61. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +0 -17
  62. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +0 -38
  63. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +0 -18
  64. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +0 -26
  65. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +0 -785
  66. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +0 -99
  67. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +0 -47
  68. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +0 -86
  69. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +0 -67
  70. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +0 -43
  71. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +0 -315
  72. data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +0 -73
  73. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +0 -100
  74. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +0 -15
  75. data/lib/jasmine-core/spec/helpers/asyncAwait.js +0 -27
  76. data/lib/jasmine-core/spec/helpers/checkForMap.js +0 -37
  77. data/lib/jasmine-core/spec/helpers/checkForSet.js +0 -41
  78. data/lib/jasmine-core/spec/helpers/checkForSymbol.js +0 -28
  79. data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +0 -20
  80. data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +0 -6
  81. data/lib/jasmine-core/spec/helpers/integrationMatchers.js +0 -43
  82. data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +0 -30
  83. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +0 -1261
  84. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +0 -18
  85. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +0 -37
  86. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +0 -27
  87. data/lib/jasmine-core/spec/html/QueryStringSpec.js +0 -72
  88. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +0 -62
  89. data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +0 -39
  90. data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +0 -48
  91. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +0 -101
  92. data/lib/jasmine-core/spec/performance/large_object_test.js +0 -36
  93. data/lib/jasmine-core/spec/performance/performance_test.js +0 -10
@@ -1,364 +0,0 @@
1
- describe("SpyRegistry", function() {
2
- function createSpy(name, originalFn) {
3
- return jasmineUnderTest.Spy(name, originalFn);
4
- }
5
-
6
- describe("#spyOn", function() {
7
- it("checks for the existence of the object", function() {
8
- var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy});
9
- expect(function() {
10
- spyRegistry.spyOn(void 0, 'pants');
11
- }).toThrowError(/could not find an object/);
12
- });
13
-
14
- it("checks that a method name was passed", function() {
15
- var spyRegistry = new jasmineUnderTest.SpyRegistry(),
16
- subject = {};
17
-
18
- expect(function() {
19
- spyRegistry.spyOn(subject);
20
- }).toThrowError(/No method name supplied/);
21
- });
22
-
23
- it("checks that the object is not `null`", function() {
24
- var spyRegistry = new jasmineUnderTest.SpyRegistry();
25
- expect(function() {
26
- spyRegistry.spyOn(null, 'pants');
27
- }).toThrowError(/could not find an object/);
28
- });
29
-
30
- it("checks that the method name is not `null`", function() {
31
- var spyRegistry = new jasmineUnderTest.SpyRegistry(),
32
- subject = {};
33
-
34
- expect(function() {
35
- spyRegistry.spyOn(subject, null);
36
- }).toThrowError(/No method name supplied/);
37
- });
38
-
39
- it("checks for the existence of the method", function() {
40
- var spyRegistry = new jasmineUnderTest.SpyRegistry(),
41
- subject = {};
42
-
43
- expect(function() {
44
- spyRegistry.spyOn(subject, 'pants');
45
- }).toThrowError(/method does not exist/);
46
- });
47
-
48
- it("checks if it has already been spied upon", function() {
49
- var spies = [],
50
- spyRegistry = new jasmineUnderTest.SpyRegistry({
51
- currentSpies: function() { return spies; },
52
- createSpy: createSpy
53
- }),
54
- subject = { spiedFunc: function() {} };
55
-
56
- spyRegistry.spyOn(subject, 'spiedFunc');
57
-
58
- expect(function() {
59
- spyRegistry.spyOn(subject, 'spiedFunc');
60
- }).toThrowError(/has already been spied upon/);
61
- });
62
-
63
- it("checks if it can be spied upon", function() {
64
- var scope = {};
65
-
66
- function myFunc() {
67
- return 1;
68
- }
69
-
70
- Object.defineProperty(scope, 'myFunc', {
71
- get: function() {
72
- return myFunc;
73
- }
74
- });
75
-
76
- var spies = [],
77
- spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
78
- subject = { spiedFunc: scope.myFunc };
79
-
80
- expect(function() {
81
- spyRegistry.spyOn(scope, 'myFunc');
82
- }).toThrowError(/is not declared writable or has no setter/);
83
-
84
- expect(function() {
85
- spyRegistry.spyOn(subject, 'spiedFunc');
86
- }).not.toThrowError(/is not declared writable or has no setter/);
87
- });
88
-
89
- it("overrides the method on the object and returns the spy", function() {
90
- var originalFunctionWasCalled = false,
91
- spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
92
- subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
93
-
94
- var spy = spyRegistry.spyOn(subject, 'spiedFunc');
95
-
96
- expect(subject.spiedFunc).toEqual(spy);
97
- });
98
- });
99
-
100
- describe("#spyOnProperty", function() {
101
- it("checks for the existence of the object", function() {
102
- var spyRegistry = new jasmineUnderTest.SpyRegistry();
103
- expect(function() {
104
- spyRegistry.spyOnProperty(void 0, 'pants');
105
- }).toThrowError(/could not find an object/);
106
- });
107
-
108
- it("checks that a property name was passed", function() {
109
- var spyRegistry = new jasmineUnderTest.SpyRegistry(),
110
- subject = {};
111
-
112
- expect(function() {
113
- spyRegistry.spyOnProperty(subject);
114
- }).toThrowError(/No property name supplied/);
115
- });
116
-
117
- it("checks for the existence of the method", function() {
118
- var spyRegistry = new jasmineUnderTest.SpyRegistry(),
119
- subject = {};
120
-
121
- expect(function() {
122
- spyRegistry.spyOnProperty(subject, 'pants');
123
- }).toThrowError(/property does not exist/);
124
- });
125
-
126
- it("checks for the existence of access type", function() {
127
- var spyRegistry = new jasmineUnderTest.SpyRegistry(),
128
- subject = {};
129
-
130
- Object.defineProperty(subject, 'pants', {
131
- get: function() { return 1; },
132
- configurable: true
133
- });
134
-
135
- expect(function() {
136
- spyRegistry.spyOnProperty(subject, 'pants', 'set');
137
- }).toThrowError(/does not have access type/);
138
- });
139
-
140
- it("checks if it has already been spied upon", function() {
141
- var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
142
- subject = {};
143
-
144
- Object.defineProperty(subject, 'spiedProp', {
145
- get: function() { return 1; },
146
- configurable: true
147
- });
148
-
149
- spyRegistry.spyOnProperty(subject, 'spiedProp');
150
-
151
- expect(function() {
152
- spyRegistry.spyOnProperty(subject, 'spiedProp');
153
- }).toThrowError(/has already been spied upon/);
154
- });
155
-
156
- it("checks if it can be spied upon", function() {
157
- var subject = {};
158
-
159
- Object.defineProperty(subject, 'myProp', {
160
- get: function() {}
161
- });
162
-
163
- Object.defineProperty(subject, 'spiedProp', {
164
- get: function() {},
165
- configurable: true
166
- });
167
-
168
- var spyRegistry = new jasmineUnderTest.SpyRegistry();
169
-
170
- expect(function() {
171
- spyRegistry.spyOnProperty(subject, 'myProp');
172
- }).toThrowError(/is not declared configurable/);
173
-
174
- expect(function() {
175
- spyRegistry.spyOnProperty(subject, 'spiedProp');
176
- }).not.toThrowError(/is not declared configurable/);
177
- });
178
-
179
- it("overrides the property getter on the object and returns the spy", function() {
180
- var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
181
- subject = {},
182
- returnValue = 1;
183
-
184
- Object.defineProperty(subject, 'spiedProperty', {
185
- get: function() { return returnValue; },
186
- configurable: true
187
- });
188
-
189
- expect(subject.spiedProperty).toEqual(returnValue);
190
-
191
- var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
192
- var getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty').get;
193
-
194
- expect(getter).toEqual(spy);
195
- expect(subject.spiedProperty).toBeUndefined();
196
- });
197
-
198
- it("overrides the property setter on the object and returns the spy", function() {
199
- var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
200
- subject = {},
201
- returnValue = 1;
202
-
203
- Object.defineProperty(subject, 'spiedProperty', {
204
- get: function() { return returnValue; },
205
- set: function() {},
206
- configurable: true
207
- });
208
-
209
- var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
210
- var setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty').set;
211
-
212
- expect(subject.spiedProperty).toEqual(returnValue);
213
- expect(setter).toEqual(spy);
214
- });
215
- });
216
-
217
- describe("#clearSpies", function() {
218
- it("restores the original functions on the spied-upon objects", function() {
219
- var spies = [],
220
- spyRegistry = new jasmineUnderTest.SpyRegistry({
221
- currentSpies: function() { return spies; },
222
- createSpy: createSpy
223
- }),
224
- originalFunction = function() {},
225
- subject = { spiedFunc: originalFunction };
226
-
227
- spyRegistry.spyOn(subject, 'spiedFunc');
228
- spyRegistry.clearSpies();
229
-
230
- expect(subject.spiedFunc).toBe(originalFunction);
231
- });
232
-
233
- it("restores the original functions, even when that spy has been replace and re-spied upon", function() {
234
- var spies = [],
235
- spyRegistry = new jasmineUnderTest.SpyRegistry({
236
- currentSpies: function() { return spies; },
237
- createSpy: createSpy
238
- }),
239
- originalFunction = function() {},
240
- subject = { spiedFunc: originalFunction };
241
-
242
- spyRegistry.spyOn(subject, 'spiedFunc');
243
-
244
- // replace the original spy with some other function
245
- subject.spiedFunc = function() {};
246
-
247
- // spy on the function in that location again
248
- spyRegistry.spyOn(subject, 'spiedFunc');
249
-
250
- spyRegistry.clearSpies();
251
-
252
- expect(subject.spiedFunc).toBe(originalFunction);
253
- });
254
-
255
- it("does not add a property that the spied-upon object didn't originally have", function() {
256
- var spies = [],
257
- spyRegistry = new jasmineUnderTest.SpyRegistry({
258
- currentSpies: function() { return spies; },
259
- createSpy: createSpy
260
- }),
261
- originalFunction = function() {},
262
- subjectParent = {spiedFunc: originalFunction};
263
-
264
- var subject = Object.create(subjectParent);
265
-
266
- expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
267
-
268
- spyRegistry.spyOn(subject, 'spiedFunc');
269
- spyRegistry.clearSpies();
270
-
271
- expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
272
- expect(subject.spiedFunc).toBe(originalFunction);
273
- });
274
-
275
- it("restores the original function when it\'s inherited and cannot be deleted", function() {
276
- var spies = [],
277
- spyRegistry = new jasmineUnderTest.SpyRegistry({
278
- currentSpies: function() { return spies; },
279
- createSpy: createSpy
280
- }),
281
- originalFunction = function() {},
282
- subjectParent = {spiedFunc: originalFunction};
283
-
284
- var subject = Object.create(subjectParent);
285
-
286
- spyRegistry.spyOn(subject, 'spiedFunc');
287
-
288
- // simulate a spy that cannot be deleted
289
- Object.defineProperty(subject, 'spiedFunc', {
290
- configurable: false
291
- });
292
-
293
- spyRegistry.clearSpies();
294
-
295
- expect(jasmineUnderTest.isSpy(subject.spiedFunc)).toBe(false);
296
- });
297
-
298
- it("restores window.onerror by overwriting, not deleting", function() {
299
- function FakeWindow() {
300
- }
301
- FakeWindow.prototype.onerror = function() {};
302
-
303
- var spies = [],
304
- global = new FakeWindow(),
305
- spyRegistry = new jasmineUnderTest.SpyRegistry({
306
- currentSpies: function() { return spies; },
307
- createSpy: createSpy,
308
- global: global
309
- });
310
-
311
- spyRegistry.spyOn(global, 'onerror');
312
- spyRegistry.clearSpies();
313
- expect(global.onerror).toBe(FakeWindow.prototype.onerror);
314
- expect(global.hasOwnProperty('onerror')).toBe(true);
315
- });
316
- });
317
-
318
- describe('spying on properties', function() {
319
- it("restores the original properties on the spied-upon objects", function() {
320
- var spies = [],
321
- spyRegistry = new jasmineUnderTest.SpyRegistry({
322
- currentSpies: function() { return spies; },
323
- createSpy: createSpy
324
- }),
325
- originalReturn = 1,
326
- subject = {};
327
-
328
- Object.defineProperty(subject, 'spiedProp', {
329
- get: function() { return originalReturn; },
330
- configurable: true
331
- });
332
-
333
- spyRegistry.spyOnProperty(subject, 'spiedProp');
334
- spyRegistry.clearSpies();
335
-
336
- expect(subject.spiedProp).toBe(originalReturn);
337
- });
338
-
339
- it("does not add a property that the spied-upon object didn't originally have", function() {
340
- var spies = [],
341
- spyRegistry = new jasmineUnderTest.SpyRegistry({
342
- currentSpies: function() { return spies; },
343
- createSpy: createSpy
344
- }),
345
- originalReturn = 1,
346
- subjectParent = {};
347
-
348
- Object.defineProperty(subjectParent, 'spiedProp', {
349
- get: function() { return originalReturn; },
350
- configurable: true
351
- });
352
-
353
- var subject = Object.create(subjectParent);
354
-
355
- expect(subject.hasOwnProperty('spiedProp')).toBe(false);
356
-
357
- spyRegistry.spyOnProperty(subject, 'spiedProp');
358
- spyRegistry.clearSpies();
359
-
360
- expect(subject.hasOwnProperty('spiedProp')).toBe(false);
361
- expect(subject.spiedProp).toBe(originalReturn);
362
- });
363
- });
364
- });
@@ -1,177 +0,0 @@
1
- describe('Spies', function () {
2
- var env;
3
-
4
- beforeEach(function() {
5
- env = new jasmineUnderTest.Env();
6
- });
7
-
8
- describe("createSpy", function() {
9
- var TestClass;
10
-
11
- beforeEach(function() {
12
- TestClass = function() {};
13
- TestClass.prototype.someFunction = function() {};
14
- TestClass.prototype.someFunction.bob = "test";
15
- });
16
-
17
- it("preserves the properties of the spied function", function() {
18
- var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
19
-
20
- expect(spy.bob).toEqual("test");
21
- });
22
-
23
- it("warns the user that we intend to overwrite an existing property", function() {
24
- TestClass.prototype.someFunction.and = "turkey";
25
-
26
- expect(function() {
27
- env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
28
- }).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
29
- });
30
-
31
- it("adds a spyStrategy and callTracker to the spy", function() {
32
- var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
33
-
34
- expect(spy.and).toEqual(jasmine.any(jasmineUnderTest.SpyStrategy));
35
- expect(spy.calls).toEqual(jasmine.any(jasmineUnderTest.CallTracker));
36
- });
37
-
38
- it("tracks the argument of calls", function () {
39
- var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
40
- var trackSpy = spyOn(spy.calls, "track");
41
-
42
- spy("arg");
43
-
44
- expect(trackSpy.calls.mostRecent().args[0].args).toEqual(["arg"]);
45
- });
46
-
47
- it("tracks the context of calls", function () {
48
- var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
49
- var trackSpy = spyOn(spy.calls, "track");
50
-
51
- var contextObject = { spyMethod: spy };
52
- contextObject.spyMethod();
53
-
54
- expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
55
- });
56
-
57
- it("tracks the return value of calls", function () {
58
- var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
59
- var trackSpy = spyOn(spy.calls, "track");
60
-
61
- spy.and.returnValue("return value");
62
- spy();
63
-
64
- expect(trackSpy.calls.mostRecent().args[0].returnValue).toEqual("return value");
65
- });
66
-
67
- it("preserves arity of original function", function () {
68
- var functions = [
69
- function nullary () {},
70
- function unary (arg) {},
71
- function binary (arg1, arg2) {},
72
- function ternary (arg1, arg2, arg3) {},
73
- function quaternary (arg1, arg2, arg3, arg4) {},
74
- function quinary (arg1, arg2, arg3, arg4, arg5) {},
75
- function senary (arg1, arg2, arg3, arg4, arg5, arg6) {}
76
- ];
77
-
78
- for (var arity = 0; arity < functions.length; arity++) {
79
- var someFunction = functions[arity],
80
- spy = env.createSpy(someFunction.name, someFunction);
81
-
82
- expect(spy.length).toEqual(arity);
83
- }
84
- });
85
- });
86
-
87
- describe("createSpyObj", function() {
88
- it("should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object", function () {
89
- var spyObj = env.createSpyObj('BaseName', {'method1': 42, 'method2': 'special sauce' });
90
-
91
- expect(spyObj.method1()).toEqual(42);
92
- expect(spyObj.method1.and.identity).toEqual('BaseName.method1');
93
-
94
- expect(spyObj.method2()).toEqual('special sauce');
95
- expect(spyObj.method2.and.identity).toEqual('BaseName.method2');
96
- });
97
-
98
-
99
- it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() {
100
- var spyObj = env.createSpyObj('BaseName', ['method1', 'method2']);
101
-
102
- expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
103
- expect(spyObj.method1.and.identity).toEqual('BaseName.method1');
104
- expect(spyObj.method2.and.identity).toEqual('BaseName.method2');
105
- });
106
-
107
- it("should allow you to omit the baseName", function() {
108
- var spyObj = env.createSpyObj(['method1', 'method2']);
109
-
110
- expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
111
- expect(spyObj.method1.and.identity).toEqual('unknown.method1');
112
- expect(spyObj.method2.and.identity).toEqual('unknown.method2');
113
- });
114
-
115
- it("should throw if you do not pass an array or object argument", function() {
116
- expect(function() {
117
- env.createSpyObj('BaseName');
118
- }).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
119
- });
120
-
121
- it("should throw if you pass an empty array argument", function() {
122
- expect(function() {
123
- env.createSpyObj('BaseName', []);
124
- }).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
125
- });
126
-
127
- it("should throw if you pass an empty object argument", function() {
128
- expect(function() {
129
- env.createSpyObj('BaseName', {});
130
- }).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
131
- });
132
- });
133
-
134
- it("can use different strategies for different arguments", function() {
135
- var spy = env.createSpy('foo');
136
- spy.and.returnValue(42);
137
- spy.withArgs('baz', 'grault').and.returnValue(-1);
138
- spy.withArgs('thud').and.returnValue('bob');
139
-
140
- expect(spy('foo')).toEqual(42);
141
- expect(spy('baz', 'grault')).toEqual(-1);
142
- expect(spy('thud')).toEqual('bob');
143
- expect(spy('baz', 'grault', 'waldo')).toEqual(42);
144
- });
145
-
146
- it("uses custom equality testers when selecting a strategy", function() {
147
- var spy = env.createSpy('foo');
148
- spy.and.returnValue(42);
149
- spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
150
-
151
- expect(spy('foo')).toEqual(-1);
152
- expect(spy({})).toEqual(42);
153
- });
154
-
155
- it("can reconfigure an argument-specific strategy", function() {
156
- var spy = env.createSpy('foo');
157
- spy.withArgs('foo').and.returnValue(42);
158
- spy.withArgs('foo').and.returnValue(17);
159
- expect(spy('foo')).toEqual(17);
160
- });
161
-
162
- describe("When withArgs is used without a base strategy", function() {
163
- it("uses the matching strategy", function() {
164
- var spy = env.createSpy('foo');
165
- spy.withArgs('baz').and.returnValue(-1);
166
-
167
- expect(spy('baz')).toEqual(-1);
168
- });
169
-
170
- it("throws if the args don't match", function() {
171
- var spy = env.createSpy('foo');
172
- spy.withArgs('bar').and.returnValue(-1);
173
-
174
- expect(function() { spy('baz', {qux: 42}); }).toThrowError('Spy \'foo\' receieved a call with arguments [ \'baz\', Object({ qux: 42 }) ] but all configured strategies specify other arguments.');
175
- });
176
- });
177
- });