much-stub 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +223 -39
- data/lib/much-stub.rb +14 -12
- data/lib/much-stub/version.rb +1 -1
- data/much-stub.gemspec +3 -3
- data/test/helper.rb +3 -3
- data/test/support/factory.rb +1 -2
- data/test/system/much-stub_tests.rb +204 -223
- data/test/unit/much-stub_tests.rb +96 -94
- metadata +5 -5
data/test/support/factory.rb
CHANGED
@@ -1,59 +1,57 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "much-stub"
|
3
3
|
|
4
4
|
module MuchStub
|
5
|
-
|
6
5
|
class SystemTests < Assert::Context
|
7
6
|
desc "MuchStub"
|
8
|
-
|
9
7
|
end
|
10
8
|
|
11
9
|
class InstanceTests < SystemTests
|
12
10
|
desc "for instance methods"
|
13
11
|
setup do
|
14
12
|
@instance = TestClass.new
|
15
|
-
MuchStub.stub(@instance, :noargs){
|
16
|
-
MuchStub.stub(@instance, :noargs).with{
|
13
|
+
MuchStub.stub(@instance, :noargs){ "default" }
|
14
|
+
MuchStub.stub(@instance, :noargs).with{ "none" }
|
17
15
|
|
18
|
-
MuchStub.stub(@instance, :withargs){
|
19
|
-
MuchStub.stub(@instance, :withargs).with(1){
|
16
|
+
MuchStub.stub(@instance, :withargs){ "default" }
|
17
|
+
MuchStub.stub(@instance, :withargs).with(1){ "one" }
|
20
18
|
|
21
|
-
MuchStub.stub(@instance, :anyargs){
|
22
|
-
MuchStub.stub(@instance, :anyargs).with(1, 2){
|
19
|
+
MuchStub.stub(@instance, :anyargs){ "default" }
|
20
|
+
MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
|
23
21
|
|
24
|
-
MuchStub.stub(@instance, :minargs){
|
25
|
-
MuchStub.stub(@instance, :minargs).with(1, 2){
|
26
|
-
MuchStub.stub(@instance, :minargs).with(1, 2, 3){
|
22
|
+
MuchStub.stub(@instance, :minargs){ "default" }
|
23
|
+
MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
|
24
|
+
MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
|
27
25
|
|
28
|
-
MuchStub.stub(@instance, :withblock){
|
26
|
+
MuchStub.stub(@instance, :withblock){ "default" }
|
29
27
|
end
|
30
28
|
subject{ @instance }
|
31
29
|
|
32
30
|
should "allow stubbing a method that doesn't take args" do
|
33
|
-
assert_equal
|
31
|
+
assert_equal "none", subject.noargs
|
34
32
|
end
|
35
33
|
|
36
34
|
should "allow stubbing a method that takes args" do
|
37
|
-
assert_equal
|
38
|
-
assert_equal
|
35
|
+
assert_equal "one", subject.withargs(1)
|
36
|
+
assert_equal "default", subject.withargs(2)
|
39
37
|
end
|
40
38
|
|
41
39
|
should "allow stubbing a method that takes any args" do
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
40
|
+
assert_equal "default", subject.anyargs
|
41
|
+
assert_equal "default", subject.anyargs(1)
|
42
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
45
43
|
end
|
46
44
|
|
47
45
|
should "allow stubbing a method that takes a minimum number of args" do
|
48
|
-
assert_equal
|
49
|
-
assert_equal
|
50
|
-
assert_equal
|
51
|
-
assert_equal
|
46
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
47
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
48
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
49
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
52
50
|
end
|
53
51
|
|
54
52
|
should "allow stubbing a method that takes a block" do
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
53
|
+
assert_equal "default", subject.withblock
|
54
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
57
55
|
end
|
58
56
|
|
59
57
|
should "not allow stubbing methods with invalid arity" do
|
@@ -79,55 +77,54 @@ module MuchStub
|
|
79
77
|
|
80
78
|
assert_raises{ subject.withblock(1) }
|
81
79
|
end
|
82
|
-
|
83
80
|
end
|
84
81
|
|
85
82
|
class ClassTests < SystemTests
|
86
83
|
desc "for singleton methods on a class"
|
87
84
|
setup do
|
88
85
|
@class = TestClass
|
89
|
-
MuchStub.stub(@class, :noargs){
|
90
|
-
MuchStub.stub(@class, :noargs).with{
|
86
|
+
MuchStub.stub(@class, :noargs){ "default" }
|
87
|
+
MuchStub.stub(@class, :noargs).with{ "none" }
|
91
88
|
|
92
|
-
MuchStub.stub(@class, :withargs){
|
93
|
-
MuchStub.stub(@class, :withargs).with(1){
|
89
|
+
MuchStub.stub(@class, :withargs){ "default" }
|
90
|
+
MuchStub.stub(@class, :withargs).with(1){ "one" }
|
94
91
|
|
95
|
-
MuchStub.stub(@class, :anyargs){
|
96
|
-
MuchStub.stub(@class, :anyargs).with(1, 2){
|
92
|
+
MuchStub.stub(@class, :anyargs){ "default" }
|
93
|
+
MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
|
97
94
|
|
98
|
-
MuchStub.stub(@class, :minargs){
|
99
|
-
MuchStub.stub(@class, :minargs).with(1, 2){
|
100
|
-
MuchStub.stub(@class, :minargs).with(1, 2, 3){
|
95
|
+
MuchStub.stub(@class, :minargs){ "default" }
|
96
|
+
MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
|
97
|
+
MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
|
101
98
|
|
102
|
-
MuchStub.stub(@class, :withblock){
|
99
|
+
MuchStub.stub(@class, :withblock){ "default" }
|
103
100
|
end
|
104
101
|
subject{ @class }
|
105
102
|
|
106
103
|
should "allow stubbing a method that doesn't take args" do
|
107
|
-
assert_equal
|
104
|
+
assert_equal "none", subject.noargs
|
108
105
|
end
|
109
106
|
|
110
107
|
should "allow stubbing a method that takes args" do
|
111
|
-
assert_equal
|
112
|
-
assert_equal
|
108
|
+
assert_equal "one", subject.withargs(1)
|
109
|
+
assert_equal "default", subject.withargs(2)
|
113
110
|
end
|
114
111
|
|
115
112
|
should "allow stubbing a method that takes any args" do
|
116
|
-
assert_equal
|
117
|
-
assert_equal
|
118
|
-
assert_equal
|
113
|
+
assert_equal "default", subject.anyargs
|
114
|
+
assert_equal "default", subject.anyargs(1)
|
115
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
119
116
|
end
|
120
117
|
|
121
118
|
should "allow stubbing a method that takes a minimum number of args" do
|
122
|
-
assert_equal
|
123
|
-
assert_equal
|
124
|
-
assert_equal
|
125
|
-
assert_equal
|
119
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
120
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
121
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
122
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
126
123
|
end
|
127
124
|
|
128
125
|
should "allow stubbing a method that takes a block" do
|
129
|
-
assert_equal
|
130
|
-
assert_equal
|
126
|
+
assert_equal "default", subject.withblock
|
127
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
131
128
|
end
|
132
129
|
|
133
130
|
should "not allow stubbing methods with invalid arity" do
|
@@ -153,55 +150,54 @@ module MuchStub
|
|
153
150
|
|
154
151
|
assert_raises{ subject.withblock(1) }
|
155
152
|
end
|
156
|
-
|
157
153
|
end
|
158
154
|
|
159
155
|
class ModuleTests < SystemTests
|
160
156
|
desc "for singleton methods on a module"
|
161
157
|
setup do
|
162
158
|
@module = TestModule
|
163
|
-
MuchStub.stub(@module, :noargs){
|
164
|
-
MuchStub.stub(@module, :noargs).with{
|
159
|
+
MuchStub.stub(@module, :noargs){ "default" }
|
160
|
+
MuchStub.stub(@module, :noargs).with{ "none" }
|
165
161
|
|
166
|
-
MuchStub.stub(@module, :withargs){
|
167
|
-
MuchStub.stub(@module, :withargs).with(1){
|
162
|
+
MuchStub.stub(@module, :withargs){ "default" }
|
163
|
+
MuchStub.stub(@module, :withargs).with(1){ "one" }
|
168
164
|
|
169
|
-
MuchStub.stub(@module, :anyargs){
|
170
|
-
MuchStub.stub(@module, :anyargs).with(1, 2){
|
165
|
+
MuchStub.stub(@module, :anyargs){ "default" }
|
166
|
+
MuchStub.stub(@module, :anyargs).with(1, 2){ "one-two" }
|
171
167
|
|
172
|
-
MuchStub.stub(@module, :minargs){
|
173
|
-
MuchStub.stub(@module, :minargs).with(1, 2){
|
174
|
-
MuchStub.stub(@module, :minargs).with(1, 2, 3){
|
168
|
+
MuchStub.stub(@module, :minargs){ "default" }
|
169
|
+
MuchStub.stub(@module, :minargs).with(1, 2){ "one-two" }
|
170
|
+
MuchStub.stub(@module, :minargs).with(1, 2, 3){ "one-two-three" }
|
175
171
|
|
176
|
-
MuchStub.stub(@module, :withblock){
|
172
|
+
MuchStub.stub(@module, :withblock){ "default" }
|
177
173
|
end
|
178
174
|
subject{ @module }
|
179
175
|
|
180
176
|
should "allow stubbing a method that doesn't take args" do
|
181
|
-
assert_equal
|
177
|
+
assert_equal "none", subject.noargs
|
182
178
|
end
|
183
179
|
|
184
180
|
should "allow stubbing a method that takes args" do
|
185
|
-
assert_equal
|
186
|
-
assert_equal
|
181
|
+
assert_equal "one", subject.withargs(1)
|
182
|
+
assert_equal "default", subject.withargs(2)
|
187
183
|
end
|
188
184
|
|
189
185
|
should "allow stubbing a method that takes any args" do
|
190
|
-
assert_equal
|
191
|
-
assert_equal
|
192
|
-
assert_equal
|
186
|
+
assert_equal "default", subject.anyargs
|
187
|
+
assert_equal "default", subject.anyargs(1)
|
188
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
193
189
|
end
|
194
190
|
|
195
191
|
should "allow stubbing a method that takes a minimum number of args" do
|
196
|
-
assert_equal
|
197
|
-
assert_equal
|
198
|
-
assert_equal
|
199
|
-
assert_equal
|
192
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
193
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
194
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
195
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
200
196
|
end
|
201
197
|
|
202
198
|
should "allow stubbing a method that takes a block" do
|
203
|
-
assert_equal
|
204
|
-
assert_equal
|
199
|
+
assert_equal "default", subject.withblock
|
200
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
205
201
|
end
|
206
202
|
|
207
203
|
should "not allow stubbing methods with invalid arity" do
|
@@ -227,55 +223,54 @@ module MuchStub
|
|
227
223
|
|
228
224
|
assert_raises{ subject.withblock(1) }
|
229
225
|
end
|
230
|
-
|
231
226
|
end
|
232
227
|
|
233
228
|
class ExtendedTests < SystemTests
|
234
229
|
desc "for extended methods"
|
235
230
|
setup do
|
236
231
|
@class = Class.new{ extend TestMixin }
|
237
|
-
MuchStub.stub(@class, :noargs){
|
238
|
-
MuchStub.stub(@class, :noargs).with{
|
232
|
+
MuchStub.stub(@class, :noargs){ "default" }
|
233
|
+
MuchStub.stub(@class, :noargs).with{ "none" }
|
239
234
|
|
240
|
-
MuchStub.stub(@class, :withargs){
|
241
|
-
MuchStub.stub(@class, :withargs).with(1){
|
235
|
+
MuchStub.stub(@class, :withargs){ "default" }
|
236
|
+
MuchStub.stub(@class, :withargs).with(1){ "one" }
|
242
237
|
|
243
|
-
MuchStub.stub(@class, :anyargs){
|
244
|
-
MuchStub.stub(@class, :anyargs).with(1, 2){
|
238
|
+
MuchStub.stub(@class, :anyargs){ "default" }
|
239
|
+
MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
|
245
240
|
|
246
|
-
MuchStub.stub(@class, :minargs){
|
247
|
-
MuchStub.stub(@class, :minargs).with(1, 2){
|
248
|
-
MuchStub.stub(@class, :minargs).with(1, 2, 3){
|
241
|
+
MuchStub.stub(@class, :minargs){ "default" }
|
242
|
+
MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
|
243
|
+
MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
|
249
244
|
|
250
|
-
MuchStub.stub(@class, :withblock){
|
245
|
+
MuchStub.stub(@class, :withblock){ "default" }
|
251
246
|
end
|
252
247
|
subject{ @class }
|
253
248
|
|
254
249
|
should "allow stubbing a method that doesn't take args" do
|
255
|
-
assert_equal
|
250
|
+
assert_equal "none", subject.noargs
|
256
251
|
end
|
257
252
|
|
258
253
|
should "allow stubbing a method that takes args" do
|
259
|
-
assert_equal
|
260
|
-
assert_equal
|
254
|
+
assert_equal "one", subject.withargs(1)
|
255
|
+
assert_equal "default", subject.withargs(2)
|
261
256
|
end
|
262
257
|
|
263
258
|
should "allow stubbing a method that takes any args" do
|
264
|
-
assert_equal
|
265
|
-
assert_equal
|
266
|
-
assert_equal
|
259
|
+
assert_equal "default", subject.anyargs
|
260
|
+
assert_equal "default", subject.anyargs(1)
|
261
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
267
262
|
end
|
268
263
|
|
269
264
|
should "allow stubbing a method that takes a minimum number of args" do
|
270
|
-
assert_equal
|
271
|
-
assert_equal
|
272
|
-
assert_equal
|
273
|
-
assert_equal
|
265
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
266
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
267
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
268
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
274
269
|
end
|
275
270
|
|
276
271
|
should "allow stubbing a method that takes a block" do
|
277
|
-
assert_equal
|
278
|
-
assert_equal
|
272
|
+
assert_equal "default", subject.withblock
|
273
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
279
274
|
end
|
280
275
|
|
281
276
|
should "not allow stubbing methods with invalid arity" do
|
@@ -301,7 +296,6 @@ module MuchStub
|
|
301
296
|
|
302
297
|
assert_raises{ subject.withblock(1) }
|
303
298
|
end
|
304
|
-
|
305
299
|
end
|
306
300
|
|
307
301
|
class IncludedTests < SystemTests
|
@@ -309,48 +303,48 @@ module MuchStub
|
|
309
303
|
setup do
|
310
304
|
@class = Class.new{ include TestMixin }
|
311
305
|
@instance = @class.new
|
312
|
-
MuchStub.stub(@instance, :noargs){
|
313
|
-
MuchStub.stub(@instance, :noargs).with{
|
306
|
+
MuchStub.stub(@instance, :noargs){ "default" }
|
307
|
+
MuchStub.stub(@instance, :noargs).with{ "none" }
|
314
308
|
|
315
|
-
MuchStub.stub(@instance, :withargs){
|
316
|
-
MuchStub.stub(@instance, :withargs).with(1){
|
309
|
+
MuchStub.stub(@instance, :withargs){ "default" }
|
310
|
+
MuchStub.stub(@instance, :withargs).with(1){ "one" }
|
317
311
|
|
318
|
-
MuchStub.stub(@instance, :anyargs){
|
319
|
-
MuchStub.stub(@instance, :anyargs).with(1, 2){
|
312
|
+
MuchStub.stub(@instance, :anyargs){ "default" }
|
313
|
+
MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
|
320
314
|
|
321
|
-
MuchStub.stub(@instance, :minargs){
|
322
|
-
MuchStub.stub(@instance, :minargs).with(1, 2){
|
323
|
-
MuchStub.stub(@instance, :minargs).with(1, 2, 3){
|
315
|
+
MuchStub.stub(@instance, :minargs){ "default" }
|
316
|
+
MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
|
317
|
+
MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
|
324
318
|
|
325
|
-
MuchStub.stub(@instance, :withblock){
|
319
|
+
MuchStub.stub(@instance, :withblock){ "default" }
|
326
320
|
end
|
327
321
|
subject{ @instance }
|
328
322
|
|
329
323
|
should "allow stubbing a method that doesn't take args" do
|
330
|
-
assert_equal
|
324
|
+
assert_equal "none", subject.noargs
|
331
325
|
end
|
332
326
|
|
333
327
|
should "allow stubbing a method that takes args" do
|
334
|
-
assert_equal
|
335
|
-
assert_equal
|
328
|
+
assert_equal "one", subject.withargs(1)
|
329
|
+
assert_equal "default", subject.withargs(2)
|
336
330
|
end
|
337
331
|
|
338
332
|
should "allow stubbing a method that takes any args" do
|
339
|
-
assert_equal
|
340
|
-
assert_equal
|
341
|
-
assert_equal
|
333
|
+
assert_equal "default", subject.anyargs
|
334
|
+
assert_equal "default", subject.anyargs(1)
|
335
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
342
336
|
end
|
343
337
|
|
344
338
|
should "allow stubbing a method that takes a minimum number of args" do
|
345
|
-
assert_equal
|
346
|
-
assert_equal
|
347
|
-
assert_equal
|
348
|
-
assert_equal
|
339
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
340
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
341
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
342
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
349
343
|
end
|
350
344
|
|
351
345
|
should "allow stubbing a method that takes a block" do
|
352
|
-
assert_equal
|
353
|
-
assert_equal
|
346
|
+
assert_equal "default", subject.withblock
|
347
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
354
348
|
end
|
355
349
|
|
356
350
|
should "not allow stubbing methods with invalid arity" do
|
@@ -376,55 +370,54 @@ module MuchStub
|
|
376
370
|
|
377
371
|
assert_raises{ subject.withblock(1) }
|
378
372
|
end
|
379
|
-
|
380
373
|
end
|
381
374
|
|
382
375
|
class InheritedClassTests < SystemTests
|
383
376
|
desc "for an inherited class method"
|
384
377
|
setup do
|
385
378
|
@class = Class.new(TestClass)
|
386
|
-
MuchStub.stub(@class, :noargs){
|
387
|
-
MuchStub.stub(@class, :noargs).with{
|
379
|
+
MuchStub.stub(@class, :noargs){ "default" }
|
380
|
+
MuchStub.stub(@class, :noargs).with{ "none" }
|
388
381
|
|
389
|
-
MuchStub.stub(@class, :withargs){
|
390
|
-
MuchStub.stub(@class, :withargs).with(1){
|
382
|
+
MuchStub.stub(@class, :withargs){ "default" }
|
383
|
+
MuchStub.stub(@class, :withargs).with(1){ "one" }
|
391
384
|
|
392
|
-
MuchStub.stub(@class, :anyargs){
|
393
|
-
MuchStub.stub(@class, :anyargs).with(1, 2){
|
385
|
+
MuchStub.stub(@class, :anyargs){ "default" }
|
386
|
+
MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
|
394
387
|
|
395
|
-
MuchStub.stub(@class, :minargs){
|
396
|
-
MuchStub.stub(@class, :minargs).with(1, 2){
|
397
|
-
MuchStub.stub(@class, :minargs).with(1, 2, 3){
|
388
|
+
MuchStub.stub(@class, :minargs){ "default" }
|
389
|
+
MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
|
390
|
+
MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
|
398
391
|
|
399
|
-
MuchStub.stub(@class, :withblock){
|
392
|
+
MuchStub.stub(@class, :withblock){ "default" }
|
400
393
|
end
|
401
394
|
subject{ @class }
|
402
395
|
|
403
396
|
should "allow stubbing a method that doesn't take args" do
|
404
|
-
assert_equal
|
397
|
+
assert_equal "none", subject.noargs
|
405
398
|
end
|
406
399
|
|
407
400
|
should "allow stubbing a method that takes args" do
|
408
|
-
assert_equal
|
409
|
-
assert_equal
|
401
|
+
assert_equal "one", subject.withargs(1)
|
402
|
+
assert_equal "default", subject.withargs(2)
|
410
403
|
end
|
411
404
|
|
412
405
|
should "allow stubbing a method that takes any args" do
|
413
|
-
assert_equal
|
414
|
-
assert_equal
|
415
|
-
assert_equal
|
406
|
+
assert_equal "default", subject.anyargs
|
407
|
+
assert_equal "default", subject.anyargs(1)
|
408
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
416
409
|
end
|
417
410
|
|
418
411
|
should "allow stubbing a method that takes a minimum number of args" do
|
419
|
-
assert_equal
|
420
|
-
assert_equal
|
421
|
-
assert_equal
|
422
|
-
assert_equal
|
412
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
413
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
414
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
415
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
423
416
|
end
|
424
417
|
|
425
418
|
should "allow stubbing a method that takes a block" do
|
426
|
-
assert_equal
|
427
|
-
assert_equal
|
419
|
+
assert_equal "default", subject.withblock
|
420
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
428
421
|
end
|
429
422
|
|
430
423
|
should "not allow stubbing methods with invalid arity" do
|
@@ -450,7 +443,6 @@ module MuchStub
|
|
450
443
|
|
451
444
|
assert_raises{ subject.withblock(1) }
|
452
445
|
end
|
453
|
-
|
454
446
|
end
|
455
447
|
|
456
448
|
class InheritedInstanceTests < SystemTests
|
@@ -458,48 +450,48 @@ module MuchStub
|
|
458
450
|
setup do
|
459
451
|
@class = Class.new(TestClass)
|
460
452
|
@instance = @class.new
|
461
|
-
MuchStub.stub(@instance, :noargs){
|
462
|
-
MuchStub.stub(@instance, :noargs).with{
|
453
|
+
MuchStub.stub(@instance, :noargs){ "default" }
|
454
|
+
MuchStub.stub(@instance, :noargs).with{ "none" }
|
463
455
|
|
464
|
-
MuchStub.stub(@instance, :withargs){
|
465
|
-
MuchStub.stub(@instance, :withargs).with(1){
|
456
|
+
MuchStub.stub(@instance, :withargs){ "default" }
|
457
|
+
MuchStub.stub(@instance, :withargs).with(1){ "one" }
|
466
458
|
|
467
|
-
MuchStub.stub(@instance, :anyargs){
|
468
|
-
MuchStub.stub(@instance, :anyargs).with(1, 2){
|
459
|
+
MuchStub.stub(@instance, :anyargs){ "default" }
|
460
|
+
MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
|
469
461
|
|
470
|
-
MuchStub.stub(@instance, :minargs){
|
471
|
-
MuchStub.stub(@instance, :minargs).with(1, 2){
|
472
|
-
MuchStub.stub(@instance, :minargs).with(1, 2, 3){
|
462
|
+
MuchStub.stub(@instance, :minargs){ "default" }
|
463
|
+
MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
|
464
|
+
MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
|
473
465
|
|
474
|
-
MuchStub.stub(@instance, :withblock){
|
466
|
+
MuchStub.stub(@instance, :withblock){ "default" }
|
475
467
|
end
|
476
468
|
subject{ @instance }
|
477
469
|
|
478
470
|
should "allow stubbing a method that doesn't take args" do
|
479
|
-
assert_equal
|
471
|
+
assert_equal "none", subject.noargs
|
480
472
|
end
|
481
473
|
|
482
474
|
should "allow stubbing a method that takes args" do
|
483
|
-
assert_equal
|
484
|
-
assert_equal
|
475
|
+
assert_equal "one", subject.withargs(1)
|
476
|
+
assert_equal "default", subject.withargs(2)
|
485
477
|
end
|
486
478
|
|
487
479
|
should "allow stubbing a method that takes any args" do
|
488
|
-
assert_equal
|
489
|
-
assert_equal
|
490
|
-
assert_equal
|
480
|
+
assert_equal "default", subject.anyargs
|
481
|
+
assert_equal "default", subject.anyargs(1)
|
482
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
491
483
|
end
|
492
484
|
|
493
485
|
should "allow stubbing a method that takes a minimum number of args" do
|
494
|
-
assert_equal
|
495
|
-
assert_equal
|
496
|
-
assert_equal
|
497
|
-
assert_equal
|
486
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
487
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
488
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
489
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
498
490
|
end
|
499
491
|
|
500
492
|
should "allow stubbing a method that takes a block" do
|
501
|
-
assert_equal
|
502
|
-
assert_equal
|
493
|
+
assert_equal "default", subject.withblock
|
494
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
503
495
|
end
|
504
496
|
|
505
497
|
should "not allow stubbing methods with invalid arity" do
|
@@ -525,55 +517,54 @@ module MuchStub
|
|
525
517
|
|
526
518
|
assert_raises{ subject.withblock(1) }
|
527
519
|
end
|
528
|
-
|
529
520
|
end
|
530
521
|
|
531
522
|
class DelegateClassTests < SystemTests
|
532
523
|
desc "a class that delegates another object"
|
533
524
|
setup do
|
534
525
|
@class = DelegateClass
|
535
|
-
MuchStub.stub(@class, :noargs){
|
536
|
-
MuchStub.stub(@class, :noargs).with{
|
526
|
+
MuchStub.stub(@class, :noargs){ "default" }
|
527
|
+
MuchStub.stub(@class, :noargs).with{ "none" }
|
537
528
|
|
538
|
-
MuchStub.stub(@class, :withargs){
|
539
|
-
MuchStub.stub(@class, :withargs).with(1){
|
529
|
+
MuchStub.stub(@class, :withargs){ "default" }
|
530
|
+
MuchStub.stub(@class, :withargs).with(1){ "one" }
|
540
531
|
|
541
|
-
MuchStub.stub(@class, :anyargs){
|
542
|
-
MuchStub.stub(@class, :anyargs).with(1, 2){
|
532
|
+
MuchStub.stub(@class, :anyargs){ "default" }
|
533
|
+
MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
|
543
534
|
|
544
|
-
MuchStub.stub(@class, :minargs){
|
545
|
-
MuchStub.stub(@class, :minargs).with(1, 2){
|
546
|
-
MuchStub.stub(@class, :minargs).with(1, 2, 3){
|
535
|
+
MuchStub.stub(@class, :minargs){ "default" }
|
536
|
+
MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
|
537
|
+
MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
|
547
538
|
|
548
|
-
MuchStub.stub(@class, :withblock){
|
539
|
+
MuchStub.stub(@class, :withblock){ "default" }
|
549
540
|
end
|
550
541
|
subject{ @class }
|
551
542
|
|
552
543
|
should "allow stubbing a method that doesn't take args" do
|
553
|
-
assert_equal
|
544
|
+
assert_equal "none", subject.noargs
|
554
545
|
end
|
555
546
|
|
556
547
|
should "allow stubbing a method that takes args" do
|
557
|
-
assert_equal
|
558
|
-
assert_equal
|
548
|
+
assert_equal "one", subject.withargs(1)
|
549
|
+
assert_equal "default", subject.withargs(2)
|
559
550
|
end
|
560
551
|
|
561
552
|
should "allow stubbing a method that takes any args" do
|
562
|
-
assert_equal
|
563
|
-
assert_equal
|
564
|
-
assert_equal
|
553
|
+
assert_equal "default", subject.anyargs
|
554
|
+
assert_equal "default", subject.anyargs(1)
|
555
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
565
556
|
end
|
566
557
|
|
567
558
|
should "allow stubbing a method that takes a minimum number of args" do
|
568
|
-
assert_equal
|
569
|
-
assert_equal
|
570
|
-
assert_equal
|
571
|
-
assert_equal
|
559
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
560
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
561
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
562
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
572
563
|
end
|
573
564
|
|
574
565
|
should "allow stubbing a method that takes a block" do
|
575
|
-
assert_equal
|
576
|
-
assert_equal
|
566
|
+
assert_equal "default", subject.withblock
|
567
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
577
568
|
end
|
578
569
|
|
579
570
|
should "allow stubbing methods with invalid arity" do
|
@@ -599,55 +590,54 @@ module MuchStub
|
|
599
590
|
|
600
591
|
assert_nothing_raised{ subject.withblock(1) }
|
601
592
|
end
|
602
|
-
|
603
593
|
end
|
604
594
|
|
605
595
|
class DelegateInstanceTests < SystemTests
|
606
596
|
desc "an instance that delegates another object"
|
607
597
|
setup do
|
608
598
|
@instance = DelegateClass.new
|
609
|
-
MuchStub.stub(@instance, :noargs){
|
610
|
-
MuchStub.stub(@instance, :noargs).with{
|
599
|
+
MuchStub.stub(@instance, :noargs){ "default" }
|
600
|
+
MuchStub.stub(@instance, :noargs).with{ "none" }
|
611
601
|
|
612
|
-
MuchStub.stub(@instance, :withargs){
|
613
|
-
MuchStub.stub(@instance, :withargs).with(1){
|
602
|
+
MuchStub.stub(@instance, :withargs){ "default" }
|
603
|
+
MuchStub.stub(@instance, :withargs).with(1){ "one" }
|
614
604
|
|
615
|
-
MuchStub.stub(@instance, :anyargs){
|
616
|
-
MuchStub.stub(@instance, :anyargs).with(1, 2){
|
605
|
+
MuchStub.stub(@instance, :anyargs){ "default" }
|
606
|
+
MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
|
617
607
|
|
618
|
-
MuchStub.stub(@instance, :minargs){
|
619
|
-
MuchStub.stub(@instance, :minargs).with(1, 2){
|
620
|
-
MuchStub.stub(@instance, :minargs).with(1, 2, 3){
|
608
|
+
MuchStub.stub(@instance, :minargs){ "default" }
|
609
|
+
MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
|
610
|
+
MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
|
621
611
|
|
622
|
-
MuchStub.stub(@instance, :withblock){
|
612
|
+
MuchStub.stub(@instance, :withblock){ "default" }
|
623
613
|
end
|
624
614
|
subject{ @instance }
|
625
615
|
|
626
616
|
should "allow stubbing a method that doesn't take args" do
|
627
|
-
assert_equal
|
617
|
+
assert_equal "none", subject.noargs
|
628
618
|
end
|
629
619
|
|
630
620
|
should "allow stubbing a method that takes args" do
|
631
|
-
assert_equal
|
632
|
-
assert_equal
|
621
|
+
assert_equal "one", subject.withargs(1)
|
622
|
+
assert_equal "default", subject.withargs(2)
|
633
623
|
end
|
634
624
|
|
635
625
|
should "allow stubbing a method that takes any args" do
|
636
|
-
assert_equal
|
637
|
-
assert_equal
|
638
|
-
assert_equal
|
626
|
+
assert_equal "default", subject.anyargs
|
627
|
+
assert_equal "default", subject.anyargs(1)
|
628
|
+
assert_equal "one-two", subject.anyargs(1, 2)
|
639
629
|
end
|
640
630
|
|
641
631
|
should "allow stubbing a method that takes a minimum number of args" do
|
642
|
-
assert_equal
|
643
|
-
assert_equal
|
644
|
-
assert_equal
|
645
|
-
assert_equal
|
632
|
+
assert_equal "one-two", subject.minargs(1, 2)
|
633
|
+
assert_equal "one-two-three", subject.minargs(1, 2, 3)
|
634
|
+
assert_equal "default", subject.minargs(1, 2, 4)
|
635
|
+
assert_equal "default", subject.minargs(1, 2, 3, 4)
|
646
636
|
end
|
647
637
|
|
648
638
|
should "allow stubbing a method that takes a block" do
|
649
|
-
assert_equal
|
650
|
-
assert_equal
|
639
|
+
assert_equal "default", subject.withblock
|
640
|
+
assert_equal "default", subject.withblock{ "my-block" }
|
651
641
|
end
|
652
642
|
|
653
643
|
should "allow stubbing methods with invalid arity" do
|
@@ -673,7 +663,6 @@ module MuchStub
|
|
673
663
|
|
674
664
|
assert_nothing_raised{ subject.withblock(1) }
|
675
665
|
end
|
676
|
-
|
677
666
|
end
|
678
667
|
|
679
668
|
class ParentAndChildClassTests < SystemTests
|
@@ -682,19 +671,17 @@ module MuchStub
|
|
682
671
|
@parent_class = Class.new
|
683
672
|
@child_class = Class.new(@parent_class)
|
684
673
|
|
685
|
-
MuchStub.stub(@parent_class, :new){
|
686
|
-
MuchStub.stub(@child_class, :new){
|
674
|
+
MuchStub.stub(@parent_class, :new){ "parent" }
|
675
|
+
MuchStub.stub(@child_class, :new){ "child" }
|
687
676
|
end
|
688
677
|
|
689
678
|
should "allow stubbing the methods individually" do
|
690
|
-
assert_equal
|
691
|
-
assert_equal
|
679
|
+
assert_equal "parent", @parent_class.new
|
680
|
+
assert_equal "child", @child_class.new
|
692
681
|
end
|
693
|
-
|
694
682
|
end
|
695
683
|
|
696
684
|
class TestClass
|
697
|
-
|
698
685
|
def self.noargs; end
|
699
686
|
def self.withargs(a); end
|
700
687
|
def self.anyargs(*args); end
|
@@ -706,27 +693,22 @@ module MuchStub
|
|
706
693
|
def anyargs(*args); end
|
707
694
|
def minargs(a, b, *args); end
|
708
695
|
def withblock(&block); end
|
709
|
-
|
710
696
|
end
|
711
697
|
|
712
698
|
module TestModule
|
713
|
-
|
714
699
|
def self.noargs; end
|
715
700
|
def self.withargs(a); end
|
716
701
|
def self.anyargs(*args); end
|
717
702
|
def self.minargs(a, b, *args); end
|
718
703
|
def self.withblock(&block); end
|
719
|
-
|
720
704
|
end
|
721
705
|
|
722
706
|
module TestMixin
|
723
|
-
|
724
707
|
def noargs; end
|
725
708
|
def withargs(a); end
|
726
709
|
def anyargs(*args); end
|
727
710
|
def minargs(a, b, *args); end
|
728
711
|
def withblock(&block); end
|
729
|
-
|
730
712
|
end
|
731
713
|
|
732
714
|
class DelegateClass
|
@@ -750,5 +732,4 @@ module MuchStub
|
|
750
732
|
@delegate.respond_to?(name) ? @delegate.send(name, *args, &block) : super
|
751
733
|
end
|
752
734
|
end
|
753
|
-
|
754
735
|
end
|