much-stub 0.1.5 → 0.1.9
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 -25
- data/lib/much-stub/version.rb +3 -1
- data/lib/much-stub.rb +82 -59
- 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 +5 -2
- data/test/unit/call_tests.rb +4 -2
- data/test/unit/much-stub_tests.rb +199 -124
- 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,32 @@ 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 mykargs(val1:, **kargs)
|
204
|
+
[val1, kargs]
|
205
|
+
end
|
206
|
+
|
207
|
+
def myblk(&block)
|
208
|
+
block.call
|
209
|
+
end
|
210
|
+
end
|
168
211
|
@myobj = @myclass.new
|
169
212
|
|
170
213
|
@stub = MuchStub::Stub.new(@myobj, :mymeth)
|
@@ -179,7 +222,10 @@ module MuchStub
|
|
179
222
|
should "generate a key given an object and method name" do
|
180
223
|
obj = @myobj
|
181
224
|
meth = :mymeth
|
182
|
-
assert_equal
|
225
|
+
assert_equal(
|
226
|
+
"--#{obj.object_id}--#{meth}--",
|
227
|
+
MuchStub::Stub.key(obj, meth),
|
228
|
+
)
|
183
229
|
end
|
184
230
|
|
185
231
|
should "know its names" do
|
@@ -216,67 +262,71 @@ module MuchStub
|
|
216
262
|
end
|
217
263
|
|
218
264
|
should "complain if stubbing a method that the object doesn't respond to" do
|
219
|
-
err =
|
220
|
-
|
265
|
+
err =
|
266
|
+
assert_raises(MuchStub::StubError) do
|
267
|
+
MuchStub::Stub.new(@myobj, :some_other_meth)
|
268
|
+
end
|
269
|
+
assert_includes "does not respond to", err.message
|
221
270
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
222
271
|
end
|
223
272
|
|
224
273
|
should "complain if stubbed and called with mismatched arity" do
|
225
274
|
MuchStub::Stub.new(@myobj, :myval){ "myval" }
|
226
275
|
err = assert_raises(MuchStub::StubArityError){ @myobj.myval }
|
227
|
-
assert_includes "arity mismatch on",
|
276
|
+
assert_includes "arity mismatch on", err.message
|
228
277
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
229
278
|
|
230
|
-
assert_nothing_raised
|
231
|
-
assert_raises(MuchStub::StubArityError){ @myobj.myval(1,2) }
|
279
|
+
assert_nothing_raised{ @myobj.myval(1) }
|
280
|
+
assert_raises(MuchStub::StubArityError){ @myobj.myval(1, 2) }
|
232
281
|
|
233
282
|
MuchStub::Stub.new(@myobj, :myargs){ "myargs" }
|
234
|
-
assert_nothing_raised
|
235
|
-
assert_nothing_raised
|
236
|
-
assert_nothing_raised
|
283
|
+
assert_nothing_raised{ @myobj.myargs }
|
284
|
+
assert_nothing_raised{ @myobj.myargs(1) }
|
285
|
+
assert_nothing_raised{ @myobj.myargs(1, 2) }
|
237
286
|
|
238
287
|
MuchStub::Stub.new(@myobj, :myvalargs){ "myvalargs" }
|
239
288
|
assert_raises(MuchStub::StubArityError){ @myobj.myvalargs }
|
240
289
|
assert_raises(MuchStub::StubArityError){ @myobj.myvalargs(1) }
|
241
|
-
assert_nothing_raised
|
242
|
-
assert_nothing_raised
|
290
|
+
assert_nothing_raised{ @myobj.myvalargs(1, 2) }
|
291
|
+
assert_nothing_raised{ @myobj.myvalargs(1, 2, 3) }
|
243
292
|
end
|
244
293
|
|
245
294
|
should "complain if stubbed with mismatched arity" do
|
246
|
-
err =
|
247
|
-
MuchStub::
|
248
|
-
|
249
|
-
|
295
|
+
err =
|
296
|
+
assert_raises(MuchStub::StubArityError) do
|
297
|
+
MuchStub::Stub.new(@myobj, :myval).with{ "myval" }
|
298
|
+
end
|
299
|
+
assert_includes "arity mismatch on", err.message
|
250
300
|
assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
|
251
301
|
|
252
302
|
assert_raises(MuchStub::StubArityError) do
|
253
|
-
MuchStub::Stub.new(@myobj, :myval).with(1,2){ "myval" }
|
303
|
+
MuchStub::Stub.new(@myobj, :myval).with(1, 2){ "myval" }
|
254
304
|
end
|
255
305
|
assert_nothing_raised do
|
256
306
|
MuchStub::Stub.new(@myobj, :myval).with(1){ "myval" }
|
257
307
|
end
|
258
308
|
|
259
309
|
assert_nothing_raised do
|
260
|
-
MuchStub::Stub.new(@myobj, :myargs).with
|
310
|
+
MuchStub::Stub.new(@myobj, :myargs).with{ "myargs" }
|
261
311
|
end
|
262
312
|
assert_nothing_raised do
|
263
|
-
MuchStub::Stub.new(@myobj, :myargs).with(1,2){ "myargs" }
|
313
|
+
MuchStub::Stub.new(@myobj, :myargs).with(1, 2){ "myargs" }
|
264
314
|
end
|
265
315
|
assert_nothing_raised do
|
266
316
|
MuchStub::Stub.new(@myobj, :myargs).with(1){ "myargs" }
|
267
317
|
end
|
268
318
|
|
269
319
|
assert_raises(MuchStub::StubArityError) do
|
270
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with
|
320
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with{ "myvalargs" }
|
271
321
|
end
|
272
322
|
assert_raises(MuchStub::StubArityError) do
|
273
323
|
MuchStub::Stub.new(@myobj, :myvalargs).with(1){ "myvalargs" }
|
274
324
|
end
|
275
325
|
assert_nothing_raised do
|
276
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with(1,2){ "myvalargs" }
|
326
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with(1, 2){ "myvalargs" }
|
277
327
|
end
|
278
328
|
assert_nothing_raised do
|
279
|
-
MuchStub::Stub.new(@myobj, :myvalargs).with(1,2,3){ "myvalargs" }
|
329
|
+
MuchStub::Stub.new(@myobj, :myvalargs).with(1, 2, 3){ "myvalargs" }
|
280
330
|
end
|
281
331
|
end
|
282
332
|
|
@@ -290,7 +340,7 @@ module MuchStub
|
|
290
340
|
|
291
341
|
should "stub methods with required arg" do
|
292
342
|
assert_equal 1, @myobj.myval(1)
|
293
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
343
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
294
344
|
assert_equal "1", @myobj.myval(1)
|
295
345
|
assert_equal "2", @myobj.myval(2)
|
296
346
|
stub.with(2){ "two" }
|
@@ -298,30 +348,36 @@ module MuchStub
|
|
298
348
|
end
|
299
349
|
|
300
350
|
should "stub methods with variable args" do
|
301
|
-
assert_equal [1,2], @myobj.myargs(1,2)
|
351
|
+
assert_equal [1, 2], @myobj.myargs(1, 2)
|
302
352
|
|
303
353
|
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)
|
354
|
+
assert_equal "1,2,3", @myobj.myargs(1, 2, 3)
|
355
|
+
stub.with(3, 4, 5){ |*args| args.join(":") }
|
356
|
+
assert_equal "3:4:5", @myobj.myargs(3, 4, 5)
|
307
357
|
|
308
|
-
stub =
|
309
|
-
|
310
|
-
|
311
|
-
|
358
|
+
stub =
|
359
|
+
MuchStub::Stub.new(@myobj, :myargs).on_call do |call|
|
360
|
+
call.args.join(",")
|
361
|
+
end
|
362
|
+
assert_equal "1,2,3", @myobj.myargs(1, 2, 3)
|
363
|
+
stub.with(3, 4, 5).on_call{ |call| call.args.join(":") }
|
364
|
+
assert_equal "3:4:5", @myobj.myargs(3, 4, 5)
|
312
365
|
end
|
313
366
|
|
314
367
|
should "stub methods with required args and variable args" do
|
315
|
-
assert_equal [1,2, [3]], @myobj.myvalargs(1,2,3)
|
368
|
+
assert_equal [1, 2, [3]], @myobj.myvalargs(1, 2, 3)
|
316
369
|
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)
|
370
|
+
assert_equal "1,2,3", @myobj.myvalargs(1, 2, 3)
|
371
|
+
stub.with(3, 4, 5){ |*args| args.join(":") }
|
372
|
+
assert_equal "3:4:5", @myobj.myvalargs(3, 4, 5)
|
320
373
|
|
321
|
-
stub =
|
322
|
-
|
323
|
-
|
324
|
-
|
374
|
+
stub =
|
375
|
+
MuchStub::Stub.new(@myobj, :myvalargs).on_call do |call|
|
376
|
+
call.args.join(",")
|
377
|
+
end
|
378
|
+
assert_equal "1,2,3", @myobj.myvalargs(1, 2, 3)
|
379
|
+
stub.with(3, 4, 5).on_call{ |call| call.args.join(":") }
|
380
|
+
assert_equal "3:4:5", @myobj.myvalargs(3, 4, 5)
|
325
381
|
end
|
326
382
|
|
327
383
|
should "stub methods that yield blocks" do
|
@@ -337,25 +393,32 @@ module MuchStub
|
|
337
393
|
end
|
338
394
|
|
339
395
|
should "stub methods even if they are not local to the object" do
|
340
|
-
mydelegatorclass =
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
396
|
+
mydelegatorclass =
|
397
|
+
Class.new do
|
398
|
+
def initialize(delegateclass)
|
399
|
+
@delegate = delegateclass.new
|
400
|
+
end
|
401
|
+
|
402
|
+
def respond_to?(meth)
|
403
|
+
@delegate.respond_to?(meth) || super
|
404
|
+
end
|
405
|
+
|
406
|
+
def method_missing(meth, *args, &block)
|
407
|
+
respond_to?(meth) ? @delegate.send(meth, *args, &block) : super
|
408
|
+
end
|
409
|
+
|
410
|
+
def respond_to_missing?(meth, _)
|
411
|
+
respond_to?(meth) || super
|
412
|
+
end
|
346
413
|
end
|
347
|
-
def method_missing(meth, *args, &block)
|
348
|
-
respond_to?(meth) ? @delegate.send(meth, *args, &block) : super
|
349
|
-
end
|
350
|
-
end
|
351
414
|
mydelegator = mydelegatorclass.new(@myclass)
|
352
415
|
|
353
|
-
assert_equal [1,2,[3]], mydelegator.myvalargs(1,2,3)
|
416
|
+
assert_equal [1, 2, [3]], mydelegator.myvalargs(1, 2, 3)
|
354
417
|
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)
|
418
|
+
assert_equal "[1, 2, 3]", mydelegator.myvalargs(1, 2, 3)
|
419
|
+
assert_equal "[4, 5, 6]", mydelegator.myvalargs(4, 5, 6)
|
420
|
+
stub.with(4, 5, 6){ "four-five-six" }
|
421
|
+
assert_equal "four-five-six", mydelegator.myvalargs(4, 5, 6)
|
359
422
|
end
|
360
423
|
|
361
424
|
should "call to the original method" do
|
@@ -363,46 +426,54 @@ module MuchStub
|
|
363
426
|
|
364
427
|
# no args
|
365
428
|
stub = MuchStub::Stub.new(@myobj, :mymeth){ "mymeth" }
|
366
|
-
assert_equal "mymeth", stub.call
|
367
|
-
assert_equal "meth", stub.call_method
|
429
|
+
assert_equal "mymeth", stub.call
|
430
|
+
assert_equal "meth", stub.call_method
|
368
431
|
|
369
432
|
# static args
|
370
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
371
|
-
assert_equal "1", stub.call(
|
372
|
-
assert_equal 1, stub.call_method(
|
373
|
-
assert_equal "2", stub.call(
|
374
|
-
assert_equal 2, stub.call_method(
|
433
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
434
|
+
assert_equal "1", stub.call(1)
|
435
|
+
assert_equal 1, stub.call_method(1)
|
436
|
+
assert_equal "2", stub.call(2)
|
437
|
+
assert_equal 2, stub.call_method(2)
|
375
438
|
stub.with(2){ "two" }
|
376
|
-
assert_equal "two", stub.call(
|
377
|
-
assert_equal 2, stub.call_method(
|
439
|
+
assert_equal "two", stub.call(2)
|
440
|
+
assert_equal 2, stub.call_method(2)
|
378
441
|
|
379
442
|
# dynamic args
|
380
443
|
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(
|
384
|
-
assert_equal [3,4,5], stub.call_method(
|
385
|
-
stub.with(3,4,5){ "three-four-five" }
|
386
|
-
assert_equal "three-four-five", stub.call(
|
387
|
-
assert_equal [3,4,5],
|
444
|
+
assert_equal "1,2", stub.call(1, 2)
|
445
|
+
assert_equal [1, 2], stub.call_method(1, 2)
|
446
|
+
assert_equal "3,4,5", stub.call(3, 4, 5)
|
447
|
+
assert_equal [3, 4, 5], stub.call_method(3, 4, 5)
|
448
|
+
stub.with(3, 4, 5){ "three-four-five" }
|
449
|
+
assert_equal "three-four-five", stub.call(3, 4, 5)
|
450
|
+
assert_equal [3, 4, 5], stub.call_method(3, 4, 5)
|
388
451
|
|
389
452
|
# mixed static/dynamic args
|
390
453
|
stub = MuchStub::Stub.new(@myobj, :myvalargs){ |*args| args.join(",") }
|
391
|
-
assert_equal "1,2,3",
|
392
|
-
assert_equal [1,2, [3]], stub.call_method(
|
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(
|
397
|
-
assert_equal [3,4,[5]],
|
454
|
+
assert_equal "1,2,3", stub.call(1, 2, 3)
|
455
|
+
assert_equal [1, 2, [3]], stub.call_method(1, 2, 3)
|
456
|
+
assert_equal "3,4,5", stub.call(3, 4, 5)
|
457
|
+
assert_equal [3, 4, [5]], stub.call_method(3, 4, 5)
|
458
|
+
stub.with(3, 4, 5){ "three-four-five" }
|
459
|
+
assert_equal "three-four-five", stub.call(3, 4, 5)
|
460
|
+
assert_equal [3, 4, [5]], stub.call_method(3, 4, 5)
|
461
|
+
|
462
|
+
# keyword args
|
463
|
+
stub = MuchStub::Stub.new(@myobj, :mykargs){ |**kargs| kargs.inspect }
|
464
|
+
assert_equal "{:val1=>1, :val2=>2}", stub.call(val1: 1, val2: 2)
|
465
|
+
assert_equal [1, { val2: 2 }], stub.call_method(val1: 1, val2: 2)
|
466
|
+
stub.with(val1: 3, val2: 4){ "three-four" }
|
467
|
+
assert_equal "three-four", stub.call(val1: 3, val2: 4)
|
468
|
+
assert_equal [3, { val2: 4 }], stub.call_method(val1: 3, val2: 4)
|
398
469
|
|
399
470
|
# blocks
|
400
471
|
blkcalled = false
|
401
472
|
blk = proc{ blkcalled = true }
|
402
473
|
stub = MuchStub::Stub.new(@myobj, :myblk){ blkcalled = "true" }
|
403
|
-
stub.call(
|
474
|
+
stub.call(&blk)
|
404
475
|
assert_equal "true", blkcalled
|
405
|
-
stub.call_method(
|
476
|
+
stub.call_method(&blk)
|
406
477
|
assert_equal true, blkcalled
|
407
478
|
end
|
408
479
|
|
@@ -414,16 +485,17 @@ module MuchStub
|
|
414
485
|
|
415
486
|
should "be removable" do
|
416
487
|
assert_equal 1, @myobj.myval(1)
|
417
|
-
stub = MuchStub::Stub.new(@myobj, :myval
|
488
|
+
stub = MuchStub::Stub.new(@myobj, :myval, &:to_s)
|
418
489
|
assert_equal "1", @myobj.myval(1)
|
419
490
|
stub.teardown
|
420
491
|
assert_equal 1, @myobj.myval(1)
|
421
492
|
end
|
422
493
|
|
423
494
|
should "have a readable inspect" do
|
424
|
-
|
425
|
-
|
426
|
-
|
495
|
+
exp =
|
496
|
+
"#<#{subject.class}:#{format("0x0%x", (subject.object_id << 1))}" \
|
497
|
+
" @method_name=#{subject.method_name.inspect}>"
|
498
|
+
assert_equal exp, subject.inspect
|
427
499
|
end
|
428
500
|
end
|
429
501
|
|
@@ -440,7 +512,7 @@ module MuchStub
|
|
440
512
|
subject{ @stub }
|
441
513
|
|
442
514
|
should "not raise a stub error when called" do
|
443
|
-
assert_nothing_raised{ @stub.call(
|
515
|
+
assert_nothing_raised{ @stub.call(@arg) }
|
444
516
|
end
|
445
517
|
end
|
446
518
|
|
@@ -463,7 +535,8 @@ module MuchStub
|
|
463
535
|
assert_equal "child", @child_class.new(1, 2)
|
464
536
|
end
|
465
537
|
|
466
|
-
should "not raise any errors when tearing down the parent before the
|
538
|
+
should "not raise any errors when tearing down the parent before the "\
|
539
|
+
"child" do
|
467
540
|
assert_nothing_raised do
|
468
541
|
@parent_stub.teardown
|
469
542
|
@child_stub.teardown
|
@@ -484,9 +557,9 @@ module MuchStub
|
|
484
557
|
class ParameterListTests < UnitTests
|
485
558
|
desc "ParameterList"
|
486
559
|
setup do
|
487
|
-
many_args = (0..ParameterList::LETTERS.size).map
|
560
|
+
many_args = (0..ParameterList::LETTERS.size).map{
|
488
561
|
Assert::Factory.string
|
489
|
-
|
562
|
+
}.join(", ")
|
490
563
|
@object = Class.new
|
491
564
|
# use `class_eval` with string to easily define methods with many params
|
492
565
|
@object.class_eval <<-methods
|
@@ -503,7 +576,7 @@ module MuchStub
|
|
503
576
|
end
|
504
577
|
|
505
578
|
should "build a parameter list for a method that takes any args" do
|
506
|
-
assert_equal "*
|
579
|
+
assert_equal "*pargs, **kargs, &block", subject.new(@object, "anyargs")
|
507
580
|
end
|
508
581
|
|
509
582
|
should "build a parameter list for a method that takes many args" do
|
@@ -511,8 +584,10 @@ module MuchStub
|
|
511
584
|
assert_equal expected, subject.new(@object, "manyargs")
|
512
585
|
end
|
513
586
|
|
514
|
-
should "build a parameter list for a method that takes a minimum number
|
515
|
-
|
587
|
+
should "build a parameter list for a method that takes a minimum number "\
|
588
|
+
"of args" do
|
589
|
+
expected =
|
590
|
+
"#{ParameterList::LETTERS.join(", ")}, aa, *pargs, **kargs, &block"
|
516
591
|
assert_equal expected, subject.new(@object, "minargs")
|
517
592
|
end
|
518
593
|
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.9
|
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:
|