much-stub 0.1.4 → 0.1.8
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 +5 -1
- data/README.md +40 -35
- data/lib/much-stub/call.rb +2 -0
- data/lib/much-stub/call_spy.rb +28 -27
- data/lib/much-stub/version.rb +3 -1
- data/lib/much-stub.rb +60 -46
- data/much-stub.gemspec +20 -12
- data/test/helper.rb +3 -1
- data/test/support/factory.rb +2 -0
- data/test/system/much-stub_tests.rb +115 -77
- data/test/unit/call_spy_tests.rb +17 -2
- data/test/unit/call_tests.rb +4 -2
- data/test/unit/much-stub_tests.rb +173 -111
- metadata +27 -9
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "much-stub"
|
3
5
|
|
@@ -14,15 +16,21 @@ module MuchStub
|
|
14
16
|
@orig_value = Factory.string
|
15
17
|
@stub_value = Factory.string
|
16
18
|
|
17
|
-
@myclass =
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
@myclass =
|
20
|
+
Class.new do
|
21
|
+
def initialize(value)
|
22
|
+
@value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def mymeth
|
26
|
+
@value
|
27
|
+
end
|
28
|
+
end
|
21
29
|
@myobj = @myclass.new(@orig_value)
|
22
30
|
end
|
23
31
|
|
24
32
|
should "build a stub" do
|
25
|
-
stub1 = MuchStub.(@myobj, :mymeth)
|
33
|
+
stub1 = MuchStub.call(@myobj, :mymeth)
|
26
34
|
assert_kind_of MuchStub::Stub, stub1
|
27
35
|
|
28
36
|
stub2 = MuchStub.stub(@myobj, :mymeth)
|
@@ -32,9 +40,9 @@ module MuchStub
|
|
32
40
|
should "build a stub with an on_call block" do
|
33
41
|
my_meth_called_with = nil
|
34
42
|
stub1 =
|
35
|
-
MuchStub.on_call(@myobj, :mymeth)
|
43
|
+
MuchStub.on_call(@myobj, :mymeth) do |call|
|
36
44
|
my_meth_called_with = call
|
37
|
-
|
45
|
+
end
|
38
46
|
|
39
47
|
@myobj.mymeth
|
40
48
|
assert_kind_of MuchStub::Stub, stub1
|
@@ -42,9 +50,9 @@ module MuchStub
|
|
42
50
|
|
43
51
|
my_meth_called_with = nil
|
44
52
|
stub2 =
|
45
|
-
MuchStub.stub_on_call(@myobj, :mymeth)
|
53
|
+
MuchStub.stub_on_call(@myobj, :mymeth) do |call|
|
46
54
|
my_meth_called_with = call
|
47
|
-
|
55
|
+
end
|
48
56
|
|
49
57
|
@myobj.mymeth
|
50
58
|
assert_kind_of MuchStub::Stub, stub2
|
@@ -52,15 +60,15 @@ module MuchStub
|
|
52
60
|
end
|
53
61
|
|
54
62
|
should "lookup stubs that have been called before" do
|
55
|
-
stub1 = MuchStub.(@myobj, :mymeth)
|
56
|
-
stub2 = MuchStub.(@myobj, :mymeth)
|
63
|
+
stub1 = MuchStub.call(@myobj, :mymeth)
|
64
|
+
stub2 = MuchStub.call(@myobj, :mymeth)
|
57
65
|
assert_same stub1, stub2
|
58
66
|
end
|
59
67
|
|
60
68
|
should "set the stub's do block if given a block" do
|
61
|
-
MuchStub.(@myobj, :mymeth)
|
69
|
+
MuchStub.call(@myobj, :mymeth)
|
62
70
|
assert_raises(MuchStub::NotStubbedError){ @myobj.mymeth }
|
63
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
71
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
64
72
|
assert_equal @stub_value, @myobj.mymeth
|
65
73
|
end
|
66
74
|
|
@@ -70,7 +78,7 @@ module MuchStub
|
|
70
78
|
assert_equal @orig_value, @myobj.mymeth
|
71
79
|
|
72
80
|
assert_equal @orig_value, @myobj.mymeth
|
73
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
81
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
74
82
|
assert_equal @stub_value, @myobj.mymeth
|
75
83
|
MuchStub.unstub(@myobj, :mymeth)
|
76
84
|
assert_equal @orig_value, @myobj.mymeth
|
@@ -79,7 +87,7 @@ module MuchStub
|
|
79
87
|
should "know and teardown all stubs" do
|
80
88
|
assert_equal @orig_value, @myobj.mymeth
|
81
89
|
|
82
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
90
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
83
91
|
assert_equal @stub_value, @myobj.mymeth
|
84
92
|
assert_equal 1, MuchStub.stubs.size
|
85
93
|
|
@@ -89,11 +97,14 @@ module MuchStub
|
|
89
97
|
end
|
90
98
|
|
91
99
|
should "be able to call a stub's original method" do
|
92
|
-
err =
|
100
|
+
err =
|
101
|
+
assert_raises(NotStubbedError) do
|
102
|
+
MuchStub.stub_send(@myobj, :mymeth)
|
103
|
+
end
|
93
104
|
assert_includes "not stubbed.", err.message
|
94
105
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
95
106
|
|
96
|
-
MuchStub.(@myobj, :mymeth){ @stub_value }
|
107
|
+
MuchStub.call(@myobj, :mymeth){ @stub_value }
|
97
108
|
|
98
109
|
assert_equal @stub_value, @myobj.mymeth
|
99
110
|
assert_equal @orig_value, MuchStub.stub_send(@myobj, :mymeth)
|
@@ -101,9 +112,9 @@ module MuchStub
|
|
101
112
|
|
102
113
|
should "be able to add a stub tap" do
|
103
114
|
my_meth_called_with = nil
|
104
|
-
MuchStub.tap(@myobj, :mymeth)
|
115
|
+
MuchStub.tap(@myobj, :mymeth) do |_value, *args|
|
105
116
|
my_meth_called_with = args
|
106
|
-
|
117
|
+
end
|
107
118
|
|
108
119
|
assert_equal @orig_value, @myobj.mymeth
|
109
120
|
assert_equal [], my_meth_called_with
|
@@ -111,21 +122,33 @@ module MuchStub
|
|
111
122
|
|
112
123
|
should "be able to add a stub tap with an on_call block" do
|
113
124
|
my_meth_called_with = nil
|
114
|
-
MuchStub.tap_on_call(@myobj, :mymeth)
|
125
|
+
MuchStub.tap_on_call(@myobj, :mymeth) do |_value, call|
|
115
126
|
my_meth_called_with = call
|
116
|
-
|
127
|
+
end
|
117
128
|
|
118
129
|
assert_equal @orig_value, @myobj.mymeth
|
119
130
|
assert_equal [], my_meth_called_with.args
|
120
131
|
end
|
121
132
|
|
122
133
|
should "be able to add a stubbed spy" do
|
123
|
-
myclass =
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
134
|
+
myclass =
|
135
|
+
Class.new do
|
136
|
+
def one
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
def two(_val)
|
141
|
+
self
|
142
|
+
end
|
143
|
+
|
144
|
+
def three
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
148
|
+
def ready?
|
149
|
+
false
|
150
|
+
end
|
151
|
+
end
|
129
152
|
myobj = myclass.new
|
130
153
|
|
131
154
|
spy =
|
@@ -135,7 +158,8 @@ module MuchStub
|
|
135
158
|
:two,
|
136
159
|
:three,
|
137
160
|
:to_s,
|
138
|
-
ready?: true
|
161
|
+
ready?: true,
|
162
|
+
)
|
139
163
|
|
140
164
|
assert_equal spy, myobj.one
|
141
165
|
assert_equal spy, myobj.two("a")
|
@@ -158,13 +182,28 @@ module MuchStub
|
|
158
182
|
class StubTests < UnitTests
|
159
183
|
desc "Stub"
|
160
184
|
setup do
|
161
|
-
@myclass =
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
185
|
+
@myclass =
|
186
|
+
Class.new do
|
187
|
+
def mymeth
|
188
|
+
"meth"
|
189
|
+
end
|
190
|
+
|
191
|
+
def myval(val)
|
192
|
+
val
|
193
|
+
end
|
194
|
+
|
195
|
+
def myargs(*args)
|
196
|
+
args
|
197
|
+
end
|
198
|
+
|
199
|
+
def myvalargs(val1, val2, *args)
|
200
|
+
[val1, val2, args]
|
201
|
+
end
|
202
|
+
|
203
|
+
def myblk(&block)
|
204
|
+
block.call
|
205
|
+
end
|
206
|
+
end
|
168
207
|
@myobj = @myclass.new
|
169
208
|
|
170
209
|
@stub = MuchStub::Stub.new(@myobj, :mymeth)
|
@@ -179,7 +218,10 @@ module MuchStub
|
|
179
218
|
should "generate a key given an object and method name" do
|
180
219
|
obj = @myobj
|
181
220
|
meth = :mymeth
|
182
|
-
assert_equal
|
221
|
+
assert_equal(
|
222
|
+
"--#{obj.object_id}--#{meth}--",
|
223
|
+
MuchStub::Stub.key(obj, meth),
|
224
|
+
)
|
183
225
|
end
|
184
226
|
|
185
227
|
should "know its names" do
|
@@ -216,67 +258,71 @@ module MuchStub
|
|
216
258
|
end
|
217
259
|
|
218
260
|
should "complain if stubbing a method that the object doesn't respond to" do
|
219
|
-
err =
|
220
|
-
|
261
|
+
err =
|
262
|
+
assert_raises(MuchStub::StubError) do
|
263
|
+
MuchStub::Stub.new(@myobj, :some_other_meth)
|
264
|
+
end
|
265
|
+
assert_includes "does not respond to", err.message
|
221
266
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
222
267
|
end
|
223
268
|
|
224
269
|
should "complain if stubbed and called with mismatched arity" do
|
225
270
|
MuchStub::Stub.new(@myobj, :myval){ "myval" }
|
226
271
|
err = assert_raises(MuchStub::StubArityError){ @myobj.myval }
|
227
|
-
assert_includes "arity mismatch on",
|
272
|
+
assert_includes "arity mismatch on", err.message
|
228
273
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
229
274
|
|
230
|
-
assert_nothing_raised
|
231
|
-
assert_raises(MuchStub::StubArityError){ @myobj.myval(1,2) }
|
275
|
+
assert_nothing_raised{ @myobj.myval(1) }
|
276
|
+
assert_raises(MuchStub::StubArityError){ @myobj.myval(1, 2) }
|
232
277
|
|
233
278
|
MuchStub::Stub.new(@myobj, :myargs){ "myargs" }
|
234
|
-
assert_nothing_raised
|
235
|
-
assert_nothing_raised
|
236
|
-
assert_nothing_raised
|
279
|
+
assert_nothing_raised{ @myobj.myargs }
|
280
|
+
assert_nothing_raised{ @myobj.myargs(1) }
|
281
|
+
assert_nothing_raised{ @myobj.myargs(1, 2) }
|
237
282
|
|
238
283
|
MuchStub::Stub.new(@myobj, :myvalargs){ "myvalargs" }
|
239
284
|
assert_raises(MuchStub::StubArityError){ @myobj.myvalargs }
|
240
285
|
assert_raises(MuchStub::StubArityError){ @myobj.myvalargs(1) }
|
241
|
-
assert_nothing_raised
|
242
|
-
assert_nothing_raised
|
286
|
+
assert_nothing_raised{ @myobj.myvalargs(1, 2) }
|
287
|
+
assert_nothing_raised{ @myobj.myvalargs(1, 2, 3) }
|
243
288
|
end
|
244
289
|
|
245
290
|
should "complain if stubbed with mismatched arity" do
|
246
|
-
err =
|
247
|
-
MuchStub::
|
248
|
-
|
249
|
-
|
291
|
+
err =
|
292
|
+
assert_raises(MuchStub::StubArityError) do
|
293
|
+
MuchStub::Stub.new(@myobj, :myval).with{ "myval" }
|
294
|
+
end
|
295
|
+
assert_includes "arity mismatch on", err.message
|
250
296
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
251
297
|
|
252
298
|
assert_raises(MuchStub::StubArityError) do
|
253
|
-
MuchStub::Stub.new(@myobj, :myval).with(1,2){ "myval" }
|
299
|
+
MuchStub::Stub.new(@myobj, :myval).with(1, 2){ "myval" }
|
254
300
|
end
|
255
301
|
assert_nothing_raised do
|
256
302
|
MuchStub::Stub.new(@myobj, :myval).with(1){ "myval" }
|
257
303
|
end
|
258
304
|
|
259
305
|
assert_nothing_raised do
|
260
|
-
MuchStub::Stub.new(@myobj, :myargs).with
|
306
|
+
MuchStub::Stub.new(@myobj, :myargs).with{ "myargs" }
|
261
307
|
end
|
262
308
|
assert_nothing_raised do
|
263
|
-
MuchStub::Stub.new(@myobj, :myargs).with(1,2){ "myargs" }
|
309
|
+
MuchStub::Stub.new(@myobj, :myargs).with(1, 2){ "myargs" }
|
264
310
|
end
|
265
311
|
assert_nothing_raised do
|
266
312
|
MuchStub::Stub.new(@myobj, :myargs).with(1){ "myargs" }
|
267
313
|
end
|
268
314
|
|
269
315
|
assert_raises(MuchStub::StubArityError) do
|
270
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with
|
316
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with{ "myvalargs" }
|
271
317
|
end
|
272
318
|
assert_raises(MuchStub::StubArityError) do
|
273
319
|
MuchStub::Stub.new(@myobj, :myvalargs).with(1){ "myvalargs" }
|
274
320
|
end
|
275
321
|
assert_nothing_raised do
|
276
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with(1,2){ "myvalargs" }
|
322
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with(1, 2){ "myvalargs" }
|
277
323
|
end
|
278
324
|
assert_nothing_raised do
|
279
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with(1,2,3){ "myvalargs" }
|
325
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with(1, 2, 3){ "myvalargs" }
|
280
326
|
end
|
281
327
|
end
|
282
328
|
|
@@ -290,7 +336,7 @@ module MuchStub
|
|
290
336
|
|
291
337
|
should "stub methods with required arg" do
|
292
338
|
assert_equal 1, @myobj.myval(1)
|
293
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
339
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
294
340
|
assert_equal "1", @myobj.myval(1)
|
295
341
|
assert_equal "2", @myobj.myval(2)
|
296
342
|
stub.with(2){ "two" }
|
@@ -298,30 +344,36 @@ module MuchStub
|
|
298
344
|
end
|
299
345
|
|
300
346
|
should "stub methods with variable args" do
|
301
|
-
assert_equal [1,2], @myobj.myargs(1,2)
|
347
|
+
assert_equal [1, 2], @myobj.myargs(1, 2)
|
302
348
|
|
303
349
|
stub = MuchStub::Stub.new(@myobj, :myargs){ |*args| args.join(",") }
|
304
|
-
assert_equal "1,2,3", @myobj.myargs(1,2,3)
|
305
|
-
stub.with(3,4,5){ |*args| args.join(":") }
|
306
|
-
assert_equal "3:4:5", @myobj.myargs(3,4,5)
|
350
|
+
assert_equal "1,2,3", @myobj.myargs(1, 2, 3)
|
351
|
+
stub.with(3, 4, 5){ |*args| args.join(":") }
|
352
|
+
assert_equal "3:4:5", @myobj.myargs(3, 4, 5)
|
307
353
|
|
308
|
-
stub =
|
309
|
-
|
310
|
-
|
311
|
-
|
354
|
+
stub =
|
355
|
+
MuchStub::Stub.new(@myobj, :myargs).on_call do |call|
|
356
|
+
call.args.join(",")
|
357
|
+
end
|
358
|
+
assert_equal "1,2,3", @myobj.myargs(1, 2, 3)
|
359
|
+
stub.with(3, 4, 5).on_call{ |call| call.args.join(":") }
|
360
|
+
assert_equal "3:4:5", @myobj.myargs(3, 4, 5)
|
312
361
|
end
|
313
362
|
|
314
363
|
should "stub methods with required args and variable args" do
|
315
|
-
assert_equal [1,2, [3]], @myobj.myvalargs(1,2,3)
|
364
|
+
assert_equal [1, 2, [3]], @myobj.myvalargs(1, 2, 3)
|
316
365
|
stub = MuchStub::Stub.new(@myobj, :myvalargs){ |*args| args.join(",") }
|
317
|
-
assert_equal "1,2,3", @myobj.myvalargs(1,2,3)
|
318
|
-
stub.with(3,4,5){ |*args| args.join(":") }
|
319
|
-
assert_equal "3:4:5", @myobj.myvalargs(3,4,5)
|
366
|
+
assert_equal "1,2,3", @myobj.myvalargs(1, 2, 3)
|
367
|
+
stub.with(3, 4, 5){ |*args| args.join(":") }
|
368
|
+
assert_equal "3:4:5", @myobj.myvalargs(3, 4, 5)
|
320
369
|
|
321
|
-
stub =
|
322
|
-
|
323
|
-
|
324
|
-
|
370
|
+
stub =
|
371
|
+
MuchStub::Stub.new(@myobj, :myvalargs).on_call do |call|
|
372
|
+
call.args.join(",")
|
373
|
+
end
|
374
|
+
assert_equal "1,2,3", @myobj.myvalargs(1, 2, 3)
|
375
|
+
stub.with(3, 4, 5).on_call{ |call| call.args.join(":") }
|
376
|
+
assert_equal "3:4:5", @myobj.myvalargs(3, 4, 5)
|
325
377
|
end
|
326
378
|
|
327
379
|
should "stub methods that yield blocks" do
|
@@ -337,25 +389,32 @@ module MuchStub
|
|
337
389
|
end
|
338
390
|
|
339
391
|
should "stub methods even if they are not local to the object" do
|
340
|
-
mydelegatorclass =
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
392
|
+
mydelegatorclass =
|
393
|
+
Class.new do
|
394
|
+
def initialize(delegateclass)
|
395
|
+
@delegate = delegateclass.new
|
396
|
+
end
|
397
|
+
|
398
|
+
def respond_to?(meth)
|
399
|
+
@delegate.respond_to?(meth) || super
|
400
|
+
end
|
401
|
+
|
402
|
+
def method_missing(meth, *args, &block)
|
403
|
+
respond_to?(meth) ? @delegate.send(meth, *args, &block) : super
|
404
|
+
end
|
405
|
+
|
406
|
+
def respond_to_missing?(meth, _)
|
407
|
+
respond_to?(meth) || super
|
408
|
+
end
|
346
409
|
end
|
347
|
-
def method_missing(meth, *args, &block)
|
348
|
-
respond_to?(meth) ? @delegate.send(meth, *args, &block) : super
|
349
|
-
end
|
350
|
-
end
|
351
410
|
mydelegator = mydelegatorclass.new(@myclass)
|
352
411
|
|
353
|
-
assert_equal [1,2,[3]], mydelegator.myvalargs(1,2,3)
|
412
|
+
assert_equal [1, 2, [3]], mydelegator.myvalargs(1, 2, 3)
|
354
413
|
stub = MuchStub::Stub.new(mydelegator, :myvalargs){ |*args| args.inspect }
|
355
|
-
assert_equal "[1, 2, 3]", mydelegator.myvalargs(1,2,3)
|
356
|
-
assert_equal "[4, 5, 6]", mydelegator.myvalargs(4,5,6)
|
357
|
-
stub.with(4,5,6){ "four-five-six" }
|
358
|
-
assert_equal "four-five-six", mydelegator.myvalargs(4,5,6)
|
414
|
+
assert_equal "[1, 2, 3]", mydelegator.myvalargs(1, 2, 3)
|
415
|
+
assert_equal "[4, 5, 6]", mydelegator.myvalargs(4, 5, 6)
|
416
|
+
stub.with(4, 5, 6){ "four-five-six" }
|
417
|
+
assert_equal "four-five-six", mydelegator.myvalargs(4, 5, 6)
|
359
418
|
end
|
360
419
|
|
361
420
|
should "call to the original method" do
|
@@ -367,7 +426,7 @@ module MuchStub
|
|
367
426
|
assert_equal "meth", stub.call_method([])
|
368
427
|
|
369
428
|
# static args
|
370
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
429
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
371
430
|
assert_equal "1", stub.call([1])
|
372
431
|
assert_equal 1, stub.call_method([1])
|
373
432
|
assert_equal "2", stub.call([2])
|
@@ -378,23 +437,23 @@ module MuchStub
|
|
378
437
|
|
379
438
|
# dynamic args
|
380
439
|
stub = MuchStub::Stub.new(@myobj, :myargs){ |*args| args.join(",") }
|
381
|
-
assert_equal "1,2",
|
382
|
-
assert_equal [1,2],
|
383
|
-
assert_equal "3,4,5", stub.call([3,4,5])
|
384
|
-
assert_equal [3,4,5], stub.call_method([3,4,5])
|
385
|
-
stub.with(3,4,5){ "three-four-five" }
|
386
|
-
assert_equal "three-four-five", stub.call([3,4,5])
|
387
|
-
assert_equal [3,4,5], stub.call_method([3,4,5])
|
440
|
+
assert_equal "1,2", stub.call([1, 2])
|
441
|
+
assert_equal [1, 2], stub.call_method([1, 2])
|
442
|
+
assert_equal "3,4,5", stub.call([3, 4, 5])
|
443
|
+
assert_equal [3, 4, 5], stub.call_method([3, 4, 5])
|
444
|
+
stub.with(3, 4, 5){ "three-four-five" }
|
445
|
+
assert_equal "three-four-five", stub.call([3, 4, 5])
|
446
|
+
assert_equal [3, 4, 5], stub.call_method([3, 4, 5])
|
388
447
|
|
389
448
|
# mixed static/dynamic args
|
390
449
|
stub = MuchStub::Stub.new(@myobj, :myvalargs){ |*args| args.join(",") }
|
391
|
-
assert_equal "1,2,3",
|
392
|
-
assert_equal [1,2, [3]], stub.call_method([1,2,3])
|
393
|
-
assert_equal "3,4,5",
|
394
|
-
assert_equal [3,4,[5]],
|
395
|
-
stub.with(3,4,5){ "three-four-five" }
|
396
|
-
assert_equal "three-four-five", stub.call([3,4,5])
|
397
|
-
assert_equal [3,4,[5]],
|
450
|
+
assert_equal "1,2,3", stub.call([1, 2, 3])
|
451
|
+
assert_equal [1, 2, [3]], stub.call_method([1, 2, 3])
|
452
|
+
assert_equal "3,4,5", stub.call([3, 4, 5])
|
453
|
+
assert_equal [3, 4, [5]], stub.call_method([3, 4, 5])
|
454
|
+
stub.with(3, 4, 5){ "three-four-five" }
|
455
|
+
assert_equal "three-four-five", stub.call([3, 4, 5])
|
456
|
+
assert_equal [3, 4, [5]], stub.call_method([3, 4, 5])
|
398
457
|
|
399
458
|
# blocks
|
400
459
|
blkcalled = false
|
@@ -414,16 +473,17 @@ module MuchStub
|
|
414
473
|
|
415
474
|
should "be removable" do
|
416
475
|
assert_equal 1, @myobj.myval(1)
|
417
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
476
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
418
477
|
assert_equal "1", @myobj.myval(1)
|
419
478
|
stub.teardown
|
420
479
|
assert_equal 1, @myobj.myval(1)
|
421
480
|
end
|
422
481
|
|
423
482
|
should "have a readable inspect" do
|
424
|
-
|
425
|
-
|
426
|
-
|
483
|
+
exp =
|
484
|
+
"#<#{subject.class}:#{format("0x0%x", (subject.object_id << 1))}" \
|
485
|
+
" @method_name=#{subject.method_name.inspect}>"
|
486
|
+
assert_equal exp, subject.inspect
|
427
487
|
end
|
428
488
|
end
|
429
489
|
|
@@ -463,7 +523,8 @@ module MuchStub
|
|
463
523
|
assert_equal "child", @child_class.new(1, 2)
|
464
524
|
end
|
465
525
|
|
466
|
-
should "not raise any errors when tearing down the parent before the
|
526
|
+
should "not raise any errors when tearing down the parent before the "\
|
527
|
+
"child" do
|
467
528
|
assert_nothing_raised do
|
468
529
|
@parent_stub.teardown
|
469
530
|
@child_stub.teardown
|
@@ -484,9 +545,9 @@ module MuchStub
|
|
484
545
|
class ParameterListTests < UnitTests
|
485
546
|
desc "ParameterList"
|
486
547
|
setup do
|
487
|
-
many_args = (0..ParameterList::LETTERS.size).map
|
548
|
+
many_args = (0..ParameterList::LETTERS.size).map{
|
488
549
|
Assert::Factory.string
|
489
|
-
|
550
|
+
}.join(", ")
|
490
551
|
@object = Class.new
|
491
552
|
# use `class_eval` with string to easily define methods with many params
|
492
553
|
@object.class_eval <<-methods
|
@@ -511,7 +572,8 @@ module MuchStub
|
|
511
572
|
assert_equal expected, subject.new(@object, "manyargs")
|
512
573
|
end
|
513
574
|
|
514
|
-
should "build a parameter list for a method that takes a minimum number
|
575
|
+
should "build a parameter list for a method that takes a minimum number "\
|
576
|
+
"of args" do
|
515
577
|
expected = "#{ParameterList::LETTERS.join(", ")}, aa, *args, &block"
|
516
578
|
assert_equal expected, subject.new(@object, "minargs")
|
517
579
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-stub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
8
8
|
- Collin Redding
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: assert
|
@@ -17,14 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 2.
|
20
|
+
version: 2.19.2
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 2.
|
27
|
+
version: 2.19.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: much-style-guide
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.6.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.6.0
|
28
42
|
description: Stubbing API for replacing method calls on objects in test runs.
|
29
43
|
email:
|
30
44
|
- kelly@kellyredding.com
|
@@ -34,6 +48,10 @@ extensions: []
|
|
34
48
|
extra_rdoc_files: []
|
35
49
|
files:
|
36
50
|
- ".gitignore"
|
51
|
+
- ".l.yml"
|
52
|
+
- ".rubocop.yml"
|
53
|
+
- ".ruby-version"
|
54
|
+
- ".t.yml"
|
37
55
|
- Gemfile
|
38
56
|
- LICENSE
|
39
57
|
- README.md
|
@@ -54,13 +72,13 @@ homepage: https://github.com/redding/much-stub
|
|
54
72
|
licenses:
|
55
73
|
- MIT
|
56
74
|
metadata: {}
|
57
|
-
post_install_message:
|
75
|
+
post_install_message:
|
58
76
|
rdoc_options: []
|
59
77
|
require_paths:
|
60
78
|
- lib
|
61
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
80
|
requirements:
|
63
|
-
- - "
|
81
|
+
- - ">="
|
64
82
|
- !ruby/object:Gem::Version
|
65
83
|
version: '2.5'
|
66
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -69,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
87
|
- !ruby/object:Gem::Version
|
70
88
|
version: '0'
|
71
89
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
-
signing_key:
|
90
|
+
rubygems_version: 3.2.29
|
91
|
+
signing_key:
|
74
92
|
specification_version: 4
|
75
93
|
summary: Stubbing API for replacing method calls on objects in test runs.
|
76
94
|
test_files:
|