much-stub 0.1.6 → 0.1.7
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/.l.yml +8 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/.t.yml +6 -0
- data/Gemfile +2 -0
- data/lib/much-stub.rb +55 -44
- data/lib/much-stub/call_spy.rb +26 -25
- data/lib/much-stub/version.rb +1 -1
- data/much-stub.gemspec +19 -11
- data/test/helper.rb +1 -1
- data/test/system/much-stub_tests.rb +113 -77
- data/test/unit/call_spy_tests.rb +3 -2
- data/test/unit/call_tests.rb +2 -2
- data/test/unit/much-stub_tests.rb +148 -93
- metadata +23 -5
data/test/unit/call_spy_tests.rb
CHANGED
@@ -75,7 +75,8 @@ class MuchStub::CallSpy
|
|
75
75
|
end
|
76
76
|
subject{ @spy }
|
77
77
|
|
78
|
-
should "return the given values instead of itself if that method is
|
78
|
+
should "return the given values instead of itself if that method is "\
|
79
|
+
"called" do
|
79
80
|
assert_false subject.get.set!("value1").any?
|
80
81
|
assert_true subject.get_called?
|
81
82
|
assert_equal ["value1"], subject.set_bang_called_with.args
|
@@ -87,7 +88,7 @@ class MuchStub::CallSpy
|
|
87
88
|
desc "when init with return value procs"
|
88
89
|
setup do
|
89
90
|
@result = Factory.boolean
|
90
|
-
@spy = @unit_class.new(any?: ->(
|
91
|
+
@spy = @unit_class.new(any?: ->(_call){ @result })
|
91
92
|
end
|
92
93
|
subject{ @spy }
|
93
94
|
|
data/test/unit/call_tests.rb
CHANGED
@@ -17,14 +17,19 @@ module MuchStub
|
|
17
17
|
@stub_value = Factory.string
|
18
18
|
|
19
19
|
@myclass = Class.new do
|
20
|
-
def initialize(value)
|
21
|
-
|
20
|
+
def initialize(value)
|
21
|
+
@value = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def mymeth
|
25
|
+
@value
|
26
|
+
end
|
22
27
|
end
|
23
28
|
@myobj = @myclass.new(@orig_value)
|
24
29
|
end
|
25
30
|
|
26
31
|
should "build a stub" do
|
27
|
-
stub1 = MuchStub.(@myobj, :mymeth)
|
32
|
+
stub1 = MuchStub.call(@myobj, :mymeth)
|
28
33
|
assert_kind_of MuchStub::Stub, stub1
|
29
34
|
|
30
35
|
stub2 = MuchStub.stub(@myobj, :mymeth)
|
@@ -34,9 +39,9 @@ module MuchStub
|
|
34
39
|
should "build a stub with an on_call block" do
|
35
40
|
my_meth_called_with = nil
|
36
41
|
stub1 =
|
37
|
-
MuchStub.on_call(@myobj, :mymeth)
|
42
|
+
MuchStub.on_call(@myobj, :mymeth) do |call|
|
38
43
|
my_meth_called_with = call
|
39
|
-
|
44
|
+
end
|
40
45
|
|
41
46
|
@myobj.mymeth
|
42
47
|
assert_kind_of MuchStub::Stub, stub1
|
@@ -44,9 +49,9 @@ module MuchStub
|
|
44
49
|
|
45
50
|
my_meth_called_with = nil
|
46
51
|
stub2 =
|
47
|
-
MuchStub.stub_on_call(@myobj, :mymeth)
|
52
|
+
MuchStub.stub_on_call(@myobj, :mymeth) do |call|
|
48
53
|
my_meth_called_with = call
|
49
|
-
|
54
|
+
end
|
50
55
|
|
51
56
|
@myobj.mymeth
|
52
57
|
assert_kind_of MuchStub::Stub, stub2
|
@@ -54,15 +59,15 @@ module MuchStub
|
|
54
59
|
end
|
55
60
|
|
56
61
|
should "lookup stubs that have been called before" do
|
57
|
-
stub1 = MuchStub.(@myobj, :mymeth)
|
58
|
-
stub2 = MuchStub.(@myobj, :mymeth)
|
62
|
+
stub1 = MuchStub.call(@myobj, :mymeth)
|
63
|
+
stub2 = MuchStub.call(@myobj, :mymeth)
|
59
64
|
assert_same stub1, stub2
|
60
65
|
end
|
61
66
|
|
62
67
|
should "set the stub's do block if given a block" do
|
63
|
-
MuchStub.(@myobj, :mymeth)
|
68
|
+
MuchStub.call(@myobj, :mymeth)
|
64
69
|
assert_raises(MuchStub::NotStubbedError){ @myobj.mymeth }
|
65
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
70
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
66
71
|
assert_equal @stub_value, @myobj.mymeth
|
67
72
|
end
|
68
73
|
|
@@ -72,7 +77,7 @@ module MuchStub
|
|
72
77
|
assert_equal @orig_value, @myobj.mymeth
|
73
78
|
|
74
79
|
assert_equal @orig_value, @myobj.mymeth
|
75
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
80
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
76
81
|
assert_equal @stub_value, @myobj.mymeth
|
77
82
|
MuchStub.unstub(@myobj, :mymeth)
|
78
83
|
assert_equal @orig_value, @myobj.mymeth
|
@@ -81,7 +86,7 @@ module MuchStub
|
|
81
86
|
should "know and teardown all stubs" do
|
82
87
|
assert_equal @orig_value, @myobj.mymeth
|
83
88
|
|
84
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
89
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
85
90
|
assert_equal @stub_value, @myobj.mymeth
|
86
91
|
assert_equal 1, MuchStub.stubs.size
|
87
92
|
|
@@ -91,11 +96,14 @@ module MuchStub
|
|
91
96
|
end
|
92
97
|
|
93
98
|
should "be able to call a stub's original method" do
|
94
|
-
err =
|
99
|
+
err =
|
100
|
+
assert_raises(NotStubbedError) do
|
101
|
+
MuchStub.stub_send(@myobj, :mymeth)
|
102
|
+
end
|
95
103
|
assert_includes "not stubbed.", err.message
|
96
104
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
97
105
|
|
98
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
106
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
99
107
|
|
100
108
|
assert_equal @stub_value, @myobj.mymeth
|
101
109
|
assert_equal @orig_value, MuchStub.stub_send(@myobj, :mymeth)
|
@@ -103,9 +111,9 @@ module MuchStub
|
|
103
111
|
|
104
112
|
should "be able to add a stub tap" do
|
105
113
|
my_meth_called_with = nil
|
106
|
-
MuchStub.tap(@myobj, :mymeth)
|
114
|
+
MuchStub.tap(@myobj, :mymeth) do |_value, *args|
|
107
115
|
my_meth_called_with = args
|
108
|
-
|
116
|
+
end
|
109
117
|
|
110
118
|
assert_equal @orig_value, @myobj.mymeth
|
111
119
|
assert_equal [], my_meth_called_with
|
@@ -113,9 +121,9 @@ module MuchStub
|
|
113
121
|
|
114
122
|
should "be able to add a stub tap with an on_call block" do
|
115
123
|
my_meth_called_with = nil
|
116
|
-
MuchStub.tap_on_call(@myobj, :mymeth)
|
124
|
+
MuchStub.tap_on_call(@myobj, :mymeth) do |_value, call|
|
117
125
|
my_meth_called_with = call
|
118
|
-
|
126
|
+
end
|
119
127
|
|
120
128
|
assert_equal @orig_value, @myobj.mymeth
|
121
129
|
assert_equal [], my_meth_called_with.args
|
@@ -123,10 +131,21 @@ module MuchStub
|
|
123
131
|
|
124
132
|
should "be able to add a stubbed spy" do
|
125
133
|
myclass = Class.new do
|
126
|
-
def one
|
127
|
-
|
128
|
-
|
129
|
-
|
134
|
+
def one
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
def two(_val)
|
139
|
+
self
|
140
|
+
end
|
141
|
+
|
142
|
+
def three
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
def ready?
|
147
|
+
false
|
148
|
+
end
|
130
149
|
end
|
131
150
|
myobj = myclass.new
|
132
151
|
|
@@ -137,7 +156,8 @@ module MuchStub
|
|
137
156
|
:two,
|
138
157
|
:three,
|
139
158
|
:to_s,
|
140
|
-
ready?: true
|
159
|
+
ready?: true,
|
160
|
+
)
|
141
161
|
|
142
162
|
assert_equal spy, myobj.one
|
143
163
|
assert_equal spy, myobj.two("a")
|
@@ -161,11 +181,25 @@ module MuchStub
|
|
161
181
|
desc "Stub"
|
162
182
|
setup do
|
163
183
|
@myclass = Class.new do
|
164
|
-
def mymeth
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
def
|
184
|
+
def mymeth
|
185
|
+
"meth"
|
186
|
+
end
|
187
|
+
|
188
|
+
def myval(val)
|
189
|
+
val
|
190
|
+
end
|
191
|
+
|
192
|
+
def myargs(*args)
|
193
|
+
args
|
194
|
+
end
|
195
|
+
|
196
|
+
def myvalargs(val1, val2, *args)
|
197
|
+
[val1, val2, args]
|
198
|
+
end
|
199
|
+
|
200
|
+
def myblk(&block)
|
201
|
+
block.call
|
202
|
+
end
|
169
203
|
end
|
170
204
|
@myobj = @myclass.new
|
171
205
|
|
@@ -181,7 +215,10 @@ module MuchStub
|
|
181
215
|
should "generate a key given an object and method name" do
|
182
216
|
obj = @myobj
|
183
217
|
meth = :mymeth
|
184
|
-
assert_equal
|
218
|
+
assert_equal(
|
219
|
+
"--#{obj.object_id}--#{meth}--",
|
220
|
+
MuchStub::Stub.key(obj, meth),
|
221
|
+
)
|
185
222
|
end
|
186
223
|
|
187
224
|
should "know its names" do
|
@@ -218,67 +255,70 @@ module MuchStub
|
|
218
255
|
end
|
219
256
|
|
220
257
|
should "complain if stubbing a method that the object doesn't respond to" do
|
221
|
-
err =
|
222
|
-
|
258
|
+
err =
|
259
|
+
assert_raises(MuchStub::StubError) do
|
260
|
+
MuchStub::Stub.new(@myobj, :some_other_meth)
|
261
|
+
end
|
262
|
+
assert_includes "does not respond to", err.message
|
223
263
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
224
264
|
end
|
225
265
|
|
226
266
|
should "complain if stubbed and called with mismatched arity" do
|
227
267
|
MuchStub::Stub.new(@myobj, :myval){ "myval" }
|
228
268
|
err = assert_raises(MuchStub::StubArityError){ @myobj.myval }
|
229
|
-
assert_includes "arity mismatch on",
|
269
|
+
assert_includes "arity mismatch on", err.message
|
230
270
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
231
271
|
|
232
|
-
assert_nothing_raised
|
233
|
-
assert_raises(MuchStub::StubArityError){ @myobj.myval(1,2) }
|
272
|
+
assert_nothing_raised{ @myobj.myval(1) }
|
273
|
+
assert_raises(MuchStub::StubArityError){ @myobj.myval(1, 2) }
|
234
274
|
|
235
275
|
MuchStub::Stub.new(@myobj, :myargs){ "myargs" }
|
236
|
-
assert_nothing_raised
|
237
|
-
assert_nothing_raised
|
238
|
-
assert_nothing_raised
|
276
|
+
assert_nothing_raised{ @myobj.myargs }
|
277
|
+
assert_nothing_raised{ @myobj.myargs(1) }
|
278
|
+
assert_nothing_raised{ @myobj.myargs(1, 2) }
|
239
279
|
|
240
280
|
MuchStub::Stub.new(@myobj, :myvalargs){ "myvalargs" }
|
241
281
|
assert_raises(MuchStub::StubArityError){ @myobj.myvalargs }
|
242
282
|
assert_raises(MuchStub::StubArityError){ @myobj.myvalargs(1) }
|
243
|
-
assert_nothing_raised
|
244
|
-
assert_nothing_raised
|
283
|
+
assert_nothing_raised{ @myobj.myvalargs(1, 2) }
|
284
|
+
assert_nothing_raised{ @myobj.myvalargs(1, 2, 3) }
|
245
285
|
end
|
246
286
|
|
247
287
|
should "complain if stubbed with mismatched arity" do
|
248
288
|
err = assert_raises(MuchStub::StubArityError) do
|
249
|
-
MuchStub::Stub.new(@myobj, :myval).with
|
289
|
+
MuchStub::Stub.new(@myobj, :myval).with{ "myval" }
|
250
290
|
end
|
251
|
-
assert_includes "arity mismatch on",
|
291
|
+
assert_includes "arity mismatch on", err.message
|
252
292
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
253
293
|
|
254
294
|
assert_raises(MuchStub::StubArityError) do
|
255
|
-
MuchStub::Stub.new(@myobj, :myval).with(1,2){ "myval" }
|
295
|
+
MuchStub::Stub.new(@myobj, :myval).with(1, 2){ "myval" }
|
256
296
|
end
|
257
297
|
assert_nothing_raised do
|
258
298
|
MuchStub::Stub.new(@myobj, :myval).with(1){ "myval" }
|
259
299
|
end
|
260
300
|
|
261
301
|
assert_nothing_raised do
|
262
|
-
MuchStub::Stub.new(@myobj, :myargs).with
|
302
|
+
MuchStub::Stub.new(@myobj, :myargs).with{ "myargs" }
|
263
303
|
end
|
264
304
|
assert_nothing_raised do
|
265
|
-
MuchStub::Stub.new(@myobj, :myargs).with(1,2){ "myargs" }
|
305
|
+
MuchStub::Stub.new(@myobj, :myargs).with(1, 2){ "myargs" }
|
266
306
|
end
|
267
307
|
assert_nothing_raised do
|
268
308
|
MuchStub::Stub.new(@myobj, :myargs).with(1){ "myargs" }
|
269
309
|
end
|
270
310
|
|
271
311
|
assert_raises(MuchStub::StubArityError) do
|
272
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with
|
312
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with{ "myvalargs" }
|
273
313
|
end
|
274
314
|
assert_raises(MuchStub::StubArityError) do
|
275
315
|
MuchStub::Stub.new(@myobj, :myvalargs).with(1){ "myvalargs" }
|
276
316
|
end
|
277
317
|
assert_nothing_raised do
|
278
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with(1,2){ "myvalargs" }
|
318
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with(1, 2){ "myvalargs" }
|
279
319
|
end
|
280
320
|
assert_nothing_raised do
|
281
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with(1,2,3){ "myvalargs" }
|
321
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with(1, 2, 3){ "myvalargs" }
|
282
322
|
end
|
283
323
|
end
|
284
324
|
|
@@ -292,7 +332,7 @@ module MuchStub
|
|
292
332
|
|
293
333
|
should "stub methods with required arg" do
|
294
334
|
assert_equal 1, @myobj.myval(1)
|
295
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
335
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
296
336
|
assert_equal "1", @myobj.myval(1)
|
297
337
|
assert_equal "2", @myobj.myval(2)
|
298
338
|
stub.with(2){ "two" }
|
@@ -300,30 +340,36 @@ module MuchStub
|
|
300
340
|
end
|
301
341
|
|
302
342
|
should "stub methods with variable args" do
|
303
|
-
assert_equal [1,2], @myobj.myargs(1,2)
|
343
|
+
assert_equal [1, 2], @myobj.myargs(1, 2)
|
304
344
|
|
305
345
|
stub = MuchStub::Stub.new(@myobj, :myargs){ |*args| args.join(",") }
|
306
|
-
assert_equal "1,2,3", @myobj.myargs(1,2,3)
|
307
|
-
stub.with(3,4,5){ |*args| args.join(":") }
|
308
|
-
assert_equal "3:4:5", @myobj.myargs(3,4,5)
|
346
|
+
assert_equal "1,2,3", @myobj.myargs(1, 2, 3)
|
347
|
+
stub.with(3, 4, 5){ |*args| args.join(":") }
|
348
|
+
assert_equal "3:4:5", @myobj.myargs(3, 4, 5)
|
309
349
|
|
310
|
-
stub =
|
311
|
-
|
312
|
-
|
313
|
-
|
350
|
+
stub =
|
351
|
+
MuchStub::Stub.new(@myobj, :myargs).on_call do |call|
|
352
|
+
call.args.join(",")
|
353
|
+
end
|
354
|
+
assert_equal "1,2,3", @myobj.myargs(1, 2, 3)
|
355
|
+
stub.with(3, 4, 5).on_call{ |call| call.args.join(":") }
|
356
|
+
assert_equal "3:4:5", @myobj.myargs(3, 4, 5)
|
314
357
|
end
|
315
358
|
|
316
359
|
should "stub methods with required args and variable args" do
|
317
|
-
assert_equal [1,2, [3]], @myobj.myvalargs(1,2,3)
|
360
|
+
assert_equal [1, 2, [3]], @myobj.myvalargs(1, 2, 3)
|
318
361
|
stub = MuchStub::Stub.new(@myobj, :myvalargs){ |*args| args.join(",") }
|
319
|
-
assert_equal "1,2,3", @myobj.myvalargs(1,2,3)
|
320
|
-
stub.with(3,4,5){ |*args| args.join(":") }
|
321
|
-
assert_equal "3:4:5", @myobj.myvalargs(3,4,5)
|
362
|
+
assert_equal "1,2,3", @myobj.myvalargs(1, 2, 3)
|
363
|
+
stub.with(3, 4, 5){ |*args| args.join(":") }
|
364
|
+
assert_equal "3:4:5", @myobj.myvalargs(3, 4, 5)
|
322
365
|
|
323
|
-
stub =
|
324
|
-
|
325
|
-
|
326
|
-
|
366
|
+
stub =
|
367
|
+
MuchStub::Stub.new(@myobj, :myvalargs).on_call do |call|
|
368
|
+
call.args.join(",")
|
369
|
+
end
|
370
|
+
assert_equal "1,2,3", @myobj.myvalargs(1, 2, 3)
|
371
|
+
stub.with(3, 4, 5).on_call{ |call| call.args.join(":") }
|
372
|
+
assert_equal "3:4:5", @myobj.myvalargs(3, 4, 5)
|
327
373
|
end
|
328
374
|
|
329
375
|
should "stub methods that yield blocks" do
|
@@ -343,21 +389,27 @@ module MuchStub
|
|
343
389
|
def initialize(delegateclass)
|
344
390
|
@delegate = delegateclass.new
|
345
391
|
end
|
392
|
+
|
346
393
|
def respond_to?(meth)
|
347
394
|
@delegate.respond_to?(meth) || super
|
348
395
|
end
|
396
|
+
|
349
397
|
def method_missing(meth, *args, &block)
|
350
398
|
respond_to?(meth) ? @delegate.send(meth, *args, &block) : super
|
351
399
|
end
|
400
|
+
|
401
|
+
def respond_to_missing?(meth, _)
|
402
|
+
respond_to?(meth) || super
|
403
|
+
end
|
352
404
|
end
|
353
405
|
mydelegator = mydelegatorclass.new(@myclass)
|
354
406
|
|
355
|
-
assert_equal [1,2,[3]], mydelegator.myvalargs(1,2,3)
|
407
|
+
assert_equal [1, 2, [3]], mydelegator.myvalargs(1, 2, 3)
|
356
408
|
stub = MuchStub::Stub.new(mydelegator, :myvalargs){ |*args| args.inspect }
|
357
|
-
assert_equal "[1, 2, 3]", mydelegator.myvalargs(1,2,3)
|
358
|
-
assert_equal "[4, 5, 6]", mydelegator.myvalargs(4,5,6)
|
359
|
-
stub.with(4,5,6){ "four-five-six" }
|
360
|
-
assert_equal "four-five-six", mydelegator.myvalargs(4,5,6)
|
409
|
+
assert_equal "[1, 2, 3]", mydelegator.myvalargs(1, 2, 3)
|
410
|
+
assert_equal "[4, 5, 6]", mydelegator.myvalargs(4, 5, 6)
|
411
|
+
stub.with(4, 5, 6){ "four-five-six" }
|
412
|
+
assert_equal "four-five-six", mydelegator.myvalargs(4, 5, 6)
|
361
413
|
end
|
362
414
|
|
363
415
|
should "call to the original method" do
|
@@ -369,7 +421,7 @@ module MuchStub
|
|
369
421
|
assert_equal "meth", stub.call_method([])
|
370
422
|
|
371
423
|
# static args
|
372
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
424
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
373
425
|
assert_equal "1", stub.call([1])
|
374
426
|
assert_equal 1, stub.call_method([1])
|
375
427
|
assert_equal "2", stub.call([2])
|
@@ -380,23 +432,23 @@ module MuchStub
|
|
380
432
|
|
381
433
|
# dynamic args
|
382
434
|
stub = MuchStub::Stub.new(@myobj, :myargs){ |*args| args.join(",") }
|
383
|
-
assert_equal "1,2",
|
384
|
-
assert_equal [1,2],
|
385
|
-
assert_equal "3,4,5", stub.call([3,4,5])
|
386
|
-
assert_equal [3,4,5], stub.call_method([3,4,5])
|
387
|
-
stub.with(3,4,5){ "three-four-five" }
|
388
|
-
assert_equal "three-four-five", stub.call([3,4,5])
|
389
|
-
assert_equal [3,4,5], stub.call_method([3,4,5])
|
435
|
+
assert_equal "1,2", stub.call([1, 2])
|
436
|
+
assert_equal [1, 2], stub.call_method([1, 2])
|
437
|
+
assert_equal "3,4,5", stub.call([3, 4, 5])
|
438
|
+
assert_equal [3, 4, 5], stub.call_method([3, 4, 5])
|
439
|
+
stub.with(3, 4, 5){ "three-four-five" }
|
440
|
+
assert_equal "three-four-five", stub.call([3, 4, 5])
|
441
|
+
assert_equal [3, 4, 5], stub.call_method([3, 4, 5])
|
390
442
|
|
391
443
|
# mixed static/dynamic args
|
392
444
|
stub = MuchStub::Stub.new(@myobj, :myvalargs){ |*args| args.join(",") }
|
393
|
-
assert_equal "1,2,3",
|
394
|
-
assert_equal [1,2, [3]], stub.call_method([1,2,3])
|
395
|
-
assert_equal "3,4,5",
|
396
|
-
assert_equal [3,4,[5]],
|
397
|
-
stub.with(3,4,5){ "three-four-five" }
|
398
|
-
assert_equal "three-four-five", stub.call([3,4,5])
|
399
|
-
assert_equal [3,4,[5]],
|
445
|
+
assert_equal "1,2,3", stub.call([1, 2, 3])
|
446
|
+
assert_equal [1, 2, [3]], stub.call_method([1, 2, 3])
|
447
|
+
assert_equal "3,4,5", stub.call([3, 4, 5])
|
448
|
+
assert_equal [3, 4, [5]], stub.call_method([3, 4, 5])
|
449
|
+
stub.with(3, 4, 5){ "three-four-five" }
|
450
|
+
assert_equal "three-four-five", stub.call([3, 4, 5])
|
451
|
+
assert_equal [3, 4, [5]], stub.call_method([3, 4, 5])
|
400
452
|
|
401
453
|
# blocks
|
402
454
|
blkcalled = false
|
@@ -416,16 +468,17 @@ module MuchStub
|
|
416
468
|
|
417
469
|
should "be removable" do
|
418
470
|
assert_equal 1, @myobj.myval(1)
|
419
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
471
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
420
472
|
assert_equal "1", @myobj.myval(1)
|
421
473
|
stub.teardown
|
422
474
|
assert_equal 1, @myobj.myval(1)
|
423
475
|
end
|
424
476
|
|
425
477
|
should "have a readable inspect" do
|
426
|
-
|
427
|
-
|
428
|
-
|
478
|
+
exp =
|
479
|
+
"#<#{subject.class}:#{format("0x0%x", (subject.object_id << 1))}" \
|
480
|
+
" @method_name=#{subject.method_name.inspect}>"
|
481
|
+
assert_equal exp, subject.inspect
|
429
482
|
end
|
430
483
|
end
|
431
484
|
|
@@ -465,7 +518,8 @@ module MuchStub
|
|
465
518
|
assert_equal "child", @child_class.new(1, 2)
|
466
519
|
end
|
467
520
|
|
468
|
-
should "not raise any errors when tearing down the parent before the
|
521
|
+
should "not raise any errors when tearing down the parent before the "\
|
522
|
+
"child" do
|
469
523
|
assert_nothing_raised do
|
470
524
|
@parent_stub.teardown
|
471
525
|
@child_stub.teardown
|
@@ -486,9 +540,9 @@ module MuchStub
|
|
486
540
|
class ParameterListTests < UnitTests
|
487
541
|
desc "ParameterList"
|
488
542
|
setup do
|
489
|
-
many_args = (0..ParameterList::LETTERS.size).map
|
543
|
+
many_args = (0..ParameterList::LETTERS.size).map{
|
490
544
|
Assert::Factory.string
|
491
|
-
|
545
|
+
}.join(", ")
|
492
546
|
@object = Class.new
|
493
547
|
# use `class_eval` with string to easily define methods with many params
|
494
548
|
@object.class_eval <<-methods
|
@@ -513,7 +567,8 @@ module MuchStub
|
|
513
567
|
assert_equal expected, subject.new(@object, "manyargs")
|
514
568
|
end
|
515
569
|
|
516
|
-
should "build a parameter list for a method that takes a minimum number
|
570
|
+
should "build a parameter list for a method that takes a minimum number "\
|
571
|
+
"of args" do
|
517
572
|
expected = "#{ParameterList::LETTERS.join(", ")}, aa, *args, &block"
|
518
573
|
assert_equal expected, subject.new(@object, "minargs")
|
519
574
|
end
|