spy 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3906b9e65a981746a6dc4e51106ed64fc925478cb73335eb8a9d46ae9fc31931
4
- data.tar.gz: 85e19b544c6ccb98616dd846db8263da3d0e8abcfd2158a5749d8988c5dc32e8
3
+ metadata.gz: eb02855e84ed97ae778d5983b8bba3e5839a6593416336a18240beb759f82b7f
4
+ data.tar.gz: df92498cacaab913d6d71d6d3e34778140d7367f741a1f1d750e96cbc2353a19
5
5
  SHA512:
6
- metadata.gz: 57544c0872ff818dc065037e1e2a10c34b1edb698ad84ebf1e184aa190d24c8663d51d011619bb6a1024c93f1d94a03a8bd6578274605a56f0b0ba06aabf6abc
7
- data.tar.gz: 43b7ca82d10759bb6083fdd76b27941425cefbcc63bc2b8a585b34d3c8e2c2659f24c1f4f32843ee1c1b8f3aee1d64c127fb769774430e77a31ea7005aeebbcb
6
+ metadata.gz: 72e822dfc3517b8bcc4d26d9ffc0db333acd4526673a765de0a19f4396292834bd0402a307d31d6ba226c5f9017a2813fba53738d5784dc00fc0aa0e66720869
7
+ data.tar.gz: 35b2c58f79ef8da6c462ba1a5739ddc2705df1544a2f75c14ecb9731c60b5f33337f94056dbf1803480699d6729f0410985194cbfe4d376852cf5417d352b8c2
@@ -84,7 +84,7 @@ module Spy
84
84
  raise NeverHookedError, "'#{method_name}' method has not been hooked" unless hooked?
85
85
 
86
86
  method_owner.send(:remove_method, method_name)
87
- if original_method && method_owner == original_method.owner
87
+ if original_method
88
88
  original_method.owner.send(:define_method, method_name, original_method)
89
89
  original_method.owner.send(original_method_visibility, method_name) if original_method_visibility
90
90
  end
@@ -217,11 +217,7 @@ module Spy
217
217
  call_plan(build_call_through_plan(object), block, *args)
218
218
  elsif @plan
219
219
  check_for_too_many_arguments!(@plan)
220
- if base_object.is_a? Class
221
- call_plan(@plan, block, object, *args)
222
- else
223
- call_plan(@plan, block, *args)
224
- end
220
+ call_plan(@plan, block, *args)
225
221
  end
226
222
  ensure
227
223
  calls << CallLog.new(object, called_from, args, block, result)
data/lib/spy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spy
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class TestClassMethod < Minitest::Test
4
+ def teardown
5
+ Spy::Agency.instance.dissolve!
6
+ end
7
+
8
+ def test_and_return
9
+ klass = Class.new do
10
+ def self.class_method(*args, &block)
11
+ end
12
+ end
13
+ received_args = nil
14
+ received_block = nil
15
+ Spy.on(klass, :class_method).and_return do |*args, &block|
16
+ received_args = args
17
+ received_block = block
18
+ end
19
+ block = -> {}
20
+ klass.class_method(:a, :b, &block)
21
+ assert_equal [:a, :b], received_args
22
+ assert_equal block, received_block
23
+ end
24
+ end
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+
3
+ module Spy
4
+ class TestUnhook < Minitest::Test
5
+ module ModuleFunctionStyle
6
+ extend self
7
+
8
+ def hello
9
+ 'hello world'
10
+ end
11
+ end
12
+
13
+ module Injected
14
+ def hello
15
+ 'hello world'
16
+ end
17
+ end
18
+
19
+ class ModuleInjectedStyle
20
+ include Injected
21
+ end
22
+
23
+ class ModuleExtendedStyle
24
+ extend Injected
25
+ end
26
+
27
+ class SingletonMethodStyle
28
+ def self.hello
29
+ 'hello world'
30
+ end
31
+ end
32
+
33
+ class InstanceMethodStyle
34
+ def hello
35
+ 'hello world'
36
+ end
37
+ end
38
+
39
+ def test_ModuleFunctionStyle
40
+ spy = Spy.on(ModuleFunctionStyle, :hello).and_return('yo')
41
+ assert_equal ModuleFunctionStyle.hello, 'yo'
42
+ spy.unhook
43
+ assert_equal ModuleFunctionStyle.hello, 'hello world'
44
+ end
45
+
46
+ def test_ModuleInjectedStyle
47
+ instance = ModuleInjectedStyle.new
48
+ spy = Spy.on(instance, :hello).and_return('yo')
49
+ assert_equal instance.hello, 'yo'
50
+ spy.unhook
51
+ assert_equal instance.hello, 'hello world'
52
+ end
53
+
54
+ def test_ModuleExtendedStyle
55
+ spy = Spy.on(ModuleExtendedStyle, :hello).and_return('yo')
56
+ assert_equal ModuleExtendedStyle.hello, 'yo'
57
+ spy.unhook
58
+ assert_equal ModuleExtendedStyle.hello, 'hello world'
59
+ end
60
+
61
+ def test_SingletonMethodStyle
62
+ spy = Spy.on(SingletonMethodStyle, :hello).and_return('yo')
63
+ assert_equal SingletonMethodStyle.hello, 'yo'
64
+ spy.unhook
65
+ assert_equal SingletonMethodStyle.hello, 'hello world'
66
+ end
67
+
68
+ def test_InstanceMethodStyle
69
+ instance = InstanceMethodStyle.new
70
+ spy = Spy.on(instance, :hello).and_return('yo')
71
+ assert_equal instance.hello, 'yo'
72
+ spy.unhook
73
+ assert_equal instance.hello, 'hello world'
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Ong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-10 00:00:00.000000000 Z
11
+ date: 2022-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -157,12 +157,14 @@ files:
157
157
  - spec/spy/to_ary_spec.rb
158
158
  - spy.gemspec
159
159
  - test/integration/test_api.rb
160
+ - test/integration/test_class_method.rb
160
161
  - test/integration/test_constant_spying.rb
161
162
  - test/integration/test_instance_method.rb
162
163
  - test/integration/test_mocking.rb
163
164
  - test/integration/test_subroutine_spying.rb
164
165
  - test/spy/test_mock.rb
165
166
  - test/spy/test_subroutine.rb
167
+ - test/spy/test_unhook.rb
166
168
  - test/support/pen.rb
167
169
  - test/test_helper.rb
168
170
  homepage: https://github.com/ryanong/spy
@@ -184,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
186
  - !ruby/object:Gem::Version
185
187
  version: '0'
186
188
  requirements: []
187
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.3.17
188
190
  signing_key:
189
191
  specification_version: 4
190
192
  summary: A simple modern mocking library that uses the spy pattern and checks method's
@@ -207,11 +209,13 @@ test_files:
207
209
  - spec/spy/stub_spec.rb
208
210
  - spec/spy/to_ary_spec.rb
209
211
  - test/integration/test_api.rb
212
+ - test/integration/test_class_method.rb
210
213
  - test/integration/test_constant_spying.rb
211
214
  - test/integration/test_instance_method.rb
212
215
  - test/integration/test_mocking.rb
213
216
  - test/integration/test_subroutine_spying.rb
214
217
  - test/spy/test_mock.rb
215
218
  - test/spy/test_subroutine.rb
219
+ - test/spy/test_unhook.rb
216
220
  - test/support/pen.rb
217
221
  - test/test_helper.rb