much-stub 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15204360d9518246e4abaa703670f75489b26364a262f61397956bcd6292bb91
4
- data.tar.gz: e53db7a648e52be63ea31d6dc930d7c009e65604d05a4e1e447edcfb3ef7b296
3
+ metadata.gz: c37bcf3b2a355483515be9eabd74c93bd93ccf5f503180409f86d18a183f6f8a
4
+ data.tar.gz: 20cab69d294b44212ccd23eb068ae17e2458576153e817c30dac08206c294c47
5
5
  SHA512:
6
- metadata.gz: 5892e22dc64f46400a115d42fb7b7da3d5b82387fda5b8c2ec5f807d6a9b47e4dca5a92d86a3a97898d5f6e85885808065d591e53aba7d78303afc1396fce4a4
7
- data.tar.gz: 4476a777e7ee869f59080f5c0bc40d2d8736d77d01588f193ea6e826f424d3abf110ca49a60437267e7e16d5578c2f6f74bb24ce810940af82154ce0e08e7199
6
+ metadata.gz: 929d09b4df2e8b85496b4a47fe67a23dde700ee751b7fa3d1b074a09db185f01ad3ff54e16a7935cd1db75fc4af58fdb9ff3482fe81d40fcfcca421ae515e265
7
+ data.tar.gz: dfbfd75bc0edc084c45eee9c62926c7c2baaec32cb28f40d670a6296e1b21c7348ee4f1d6926d02b03a63223e1369b2d0907735c2b8849805862404afffd256f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.8
1
+ 3.0.2
data/Gemfile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- ruby "~> 2.5"
5
+ ruby ">= 2.5"
6
6
 
7
7
  gemspec
8
8
 
data/README.md CHANGED
@@ -16,15 +16,16 @@ Note: this was originally implemented in and extracted from [Assert](https://git
16
16
  ```ruby
17
17
  # Given this object/API
18
18
 
19
- my_class = Class.new do
20
- def my_method
21
- "my-method"
19
+ my_class =
20
+ Class.new do
21
+ def my_method
22
+ "my-method"
23
+ end
24
+
25
+ def my_value(value)
26
+ value
27
+ end
22
28
  end
23
-
24
- def my_value(value)
25
- value
26
- end
27
- end
28
29
  my_object = my_class.new
29
30
 
30
31
  my_object.my_method
@@ -95,15 +96,16 @@ my_object.my_value(456)
95
96
  ```ruby
96
97
  # Given this object/API
97
98
 
98
- my_class = Class.new do
99
- def basic_method(value)
100
- value
101
- end
99
+ my_class =
100
+ Class.new do
101
+ def basic_method(value)
102
+ value
103
+ end
102
104
 
103
- def iterator_method(items, &block)
104
- items.each(&block)
105
+ def iterator_method(items, &block)
106
+ items.each(&block)
107
+ end
105
108
  end
106
- end
107
109
  my_object = my_class.new
108
110
 
109
111
  # Store method call arguments/blocks for spying.
@@ -189,11 +191,12 @@ basic_method_calls.first.args
189
191
  ```ruby
190
192
  # Given this object/API ...
191
193
 
192
- my_class = Class.new do
193
- def build_thing(thing_value);
194
- Thing.new(value)
194
+ my_class =
195
+ Class.new do
196
+ def build_thing(thing_value);
197
+ Thing.new(value)
198
+ end
195
199
  end
196
- end
197
200
  my_object = my_class.new
198
201
 
199
202
  # ... and this Test Double.
@@ -223,11 +226,12 @@ Use the `.tap` method to spy on method calls while preserving the original metho
223
226
  ```ruby
224
227
  # Given this object/API
225
228
 
226
- my_class = Class.new do
227
- def basic_method(value)
228
- value.to_s
229
+ my_class =
230
+ Class.new do
231
+ def basic_method(value)
232
+ value.to_s
233
+ end
229
234
  end
230
- end
231
235
  my_object = my_class.new
232
236
 
233
237
  # Normal stubs override the original behavior and return value...
@@ -275,11 +279,12 @@ class Thing
275
279
  end
276
280
  end
277
281
 
278
- my_class = Class.new do
279
- def thing(value)
280
- Thing.new(value)
282
+ my_class =
283
+ Class.new do
284
+ def thing(value)
285
+ Thing.new(value)
286
+ end
281
287
  end
282
- end
283
288
  my_object = my_class.new
284
289
 
285
290
  # Use `MuchStub.tap` to stub any thing instances created by `my_object.thing`
@@ -306,16 +311,16 @@ Use the `.spy` method to spy on method calls. This is especially helpful for spy
306
311
  ```ruby
307
312
  # Given this object/API
308
313
 
309
- myclass = Class.new do
310
- def one; self; end
311
- def two(val); self; end
312
- def three; self; end
313
- def ready?; false; end
314
- end
314
+ myclass =
315
+ Class.new do
316
+ def one; self; end
317
+ def two(val); self; end
318
+ def three; self; end
319
+ def ready?; false; end
320
+ end
315
321
  myobj = myclass.new
316
322
 
317
- spy =
318
- MuchStub.spy(myobj :one, :two, :three, ready?: true)
323
+ spy = MuchStub.spy(myobj :one, :two, :three, ready?: true)
319
324
 
320
325
  assert_equal spy, myobj.one
321
326
  assert_equal spy, myobj.two("a")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuchStub
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
data/lib/much-stub.rb CHANGED
@@ -52,9 +52,10 @@ module MuchStub
52
52
 
53
53
  def self.stub_send(obj, meth, *args, &block)
54
54
  orig_caller = caller_locations
55
- stub = stubs.fetch(MuchStub::Stub.key(obj, meth)) do
56
- raise NotStubbedError, "`#{meth}` not stubbed.", orig_caller.map(&:to_s)
57
- end
55
+ stub =
56
+ stubs.fetch(MuchStub::Stub.key(obj, meth)) do
57
+ raise NotStubbedError, "`#{meth}` not stubbed.", orig_caller.map(&:to_s)
58
+ end
58
59
  stub.call_method(args, &block)
59
60
  end
60
61
 
data/much-stub.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
25
25
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
26
  gem.require_paths = ["lib"]
27
27
 
28
- gem.required_ruby_version = "~> 2.5"
28
+ gem.required_ruby_version = ">= 2.5"
29
29
 
30
30
  gem.add_development_dependency("assert", ["~> 2.19.2"])
31
31
  gem.add_development_dependency("much-style-guide", ["~> 0.6.0"])
@@ -16,15 +16,16 @@ module MuchStub
16
16
  @orig_value = Factory.string
17
17
  @stub_value = Factory.string
18
18
 
19
- @myclass = Class.new do
20
- def initialize(value)
21
- @value = value
19
+ @myclass =
20
+ Class.new do
21
+ def initialize(value)
22
+ @value = value
23
+ end
24
+
25
+ def mymeth
26
+ @value
27
+ end
22
28
  end
23
-
24
- def mymeth
25
- @value
26
- end
27
- end
28
29
  @myobj = @myclass.new(@orig_value)
29
30
  end
30
31
 
@@ -130,23 +131,24 @@ module MuchStub
130
131
  end
131
132
 
132
133
  should "be able to add a stubbed spy" do
133
- myclass = Class.new do
134
- def one
135
- self
136
- end
137
-
138
- def two(_val)
139
- self
140
- end
141
-
142
- def three
143
- self
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
144
151
  end
145
-
146
- def ready?
147
- false
148
- end
149
- end
150
152
  myobj = myclass.new
151
153
 
152
154
  spy =
@@ -180,27 +182,28 @@ module MuchStub
180
182
  class StubTests < UnitTests
181
183
  desc "Stub"
182
184
  setup do
183
- @myclass = Class.new do
184
- def mymeth
185
- "meth"
186
- end
187
-
188
- def myval(val)
189
- val
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
190
206
  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
203
- end
204
207
  @myobj = @myclass.new
205
208
 
206
209
  @stub = MuchStub::Stub.new(@myobj, :mymeth)
@@ -285,9 +288,10 @@ module MuchStub
285
288
  end
286
289
 
287
290
  should "complain if stubbed with mismatched arity" do
288
- err = assert_raises(MuchStub::StubArityError) do
289
- MuchStub::Stub.new(@myobj, :myval).with{ "myval" }
290
- end
291
+ err =
292
+ assert_raises(MuchStub::StubArityError) do
293
+ MuchStub::Stub.new(@myobj, :myval).with{ "myval" }
294
+ end
291
295
  assert_includes "arity mismatch on", err.message
292
296
  assert_includes "test/unit/much-stub_tests.rb", err.backtrace.first
293
297
 
@@ -385,23 +389,24 @@ module MuchStub
385
389
  end
386
390
 
387
391
  should "stub methods even if they are not local to the object" do
388
- mydelegatorclass = Class.new do
389
- def initialize(delegateclass)
390
- @delegate = delegateclass.new
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
391
409
  end
392
-
393
- def respond_to?(meth)
394
- @delegate.respond_to?(meth) || super
395
- end
396
-
397
- def method_missing(meth, *args, &block)
398
- respond_to?(meth) ? @delegate.send(meth, *args, &block) : super
399
- end
400
-
401
- def respond_to_missing?(meth, _)
402
- respond_to?(meth) || super
403
- end
404
- end
405
410
  mydelegator = mydelegatorclass.new(@myclass)
406
411
 
407
412
  assert_equal [1, 2, [3]], mydelegator.myvalargs(1, 2, 3)
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.7
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: 2021-01-10 00:00:00.000000000 Z
12
+ date: 2021-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert
@@ -72,13 +72,13 @@ homepage: https://github.com/redding/much-stub
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}
75
- post_install_message:
75
+ post_install_message:
76
76
  rdoc_options: []
77
77
  require_paths:
78
78
  - lib
79
79
  required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '2.5'
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.2.4
91
- signing_key:
90
+ rubygems_version: 3.2.29
91
+ signing_key:
92
92
  specification_version: 4
93
93
  summary: Stubbing API for replacing method calls on objects in test runs.
94
94
  test_files: