mock_proxy 0.1.1 → 0.1.2
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/lib/mock_proxy.rb +12 -9
- data/lib/mock_proxy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceef8aba92781d19960ef4b65b3ece2d8d1d3d4e
|
4
|
+
data.tar.gz: 41a93d0fed086e3b9479c60d055b7a7e89a0541a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9792f03d43756a82d7d8cec9b3a72e371205e9caa7904b0915209c49e5755029a1c5bcec58fd3e41a1f4c968df8e7af0f4f064ef9876cbf149573fac27aea1b0
|
7
|
+
data.tar.gz: 00e2f0de77ffc357f4a175bdd2c143dca74790a0db3c7a6d2433174d160304995d56efd6936da024432f089cd3447c078a1aad8f41aa6a0849104cf97a8faa6f
|
data/lib/mock_proxy.rb
CHANGED
@@ -51,14 +51,17 @@ class MockProxy
|
|
51
51
|
# Use case: Retrieve proc to mock
|
52
52
|
#
|
53
53
|
# @param [MockProxy] proxy existing proxy
|
54
|
-
# @param [String, Array<String>] key_path the chain of methods or key path. Can be a
|
54
|
+
# @param [String, Symbol, #to_s, Array<String, Symbol, #to_s>] key_path the chain of methods or key path. Can be a
|
55
55
|
# dot delimited key path or an array of method names as strings or symbols
|
56
56
|
# @return [Block]
|
57
57
|
def self.get(proxy, key_path)
|
58
58
|
get_callback(proxy, key_path)
|
59
59
|
end
|
60
60
|
|
61
|
-
# Deep merges the callback tree, replacing existing values with new values
|
61
|
+
# Deep merges the callback tree, replacing existing values with new values.
|
62
|
+
# Avoid using this method for one method change; prefer replace_at. It has clearer
|
63
|
+
# intent and less chances to mess up. MockProxy.merge uses deep_merge under the hood and
|
64
|
+
# can have unexpected behaviour. It also does not type check. Use at risk
|
62
65
|
#
|
63
66
|
# Use case: Reuse existing stub but with some different values
|
64
67
|
#
|
@@ -78,7 +81,7 @@ class MockProxy
|
|
78
81
|
# Use case: Reuse existing stub but modify a proc
|
79
82
|
#
|
80
83
|
# @param [MockProxy] proxy existing proxy
|
81
|
-
# @param [String, Array<String>] key_path the chain of methods or key path. Can be a
|
84
|
+
# @param [String, Symbol, #to_s, Array<String, Symbol, #to_s>] key_path the chain of methods or key path. Can be a
|
82
85
|
# dot delimited key path or an array of method names as strings or symbols
|
83
86
|
# @return [MockProxy] the original proxy object
|
84
87
|
def self.replace_at(proxy, key_path, &block)
|
@@ -91,7 +94,7 @@ class MockProxy
|
|
91
94
|
# Use case: Observe method call without changing the existing callback's stubbed return value
|
92
95
|
#
|
93
96
|
# @param [MockProxy] proxy existing proxy
|
94
|
-
# @param [String, Array<String>] key_path the chain of methods or key path. Can be a
|
97
|
+
# @param [String, Symbol, #to_s, Array<String, Symbol, #to_s>] key_path the chain of methods or key path. Can be a
|
95
98
|
# dot delimited key path or an array of method names as strings or symbols
|
96
99
|
# @yieldparam [*args] args
|
97
100
|
# @yieldreturn [optional]
|
@@ -114,7 +117,7 @@ class MockProxy
|
|
114
117
|
# Use case: Get full control of the existing proc while running custom code
|
115
118
|
#
|
116
119
|
# @param [MockProxy] proxy existing proxy
|
117
|
-
# @param [String, Array<String>] key_path the chain of methods or key path. Can be a
|
120
|
+
# @param [String, Symbol, #to_s, Array<String, Symbol, #to_s>] key_path the chain of methods or key path. Can be a
|
118
121
|
# dot delimited key path or an array of method names as strings or symbols
|
119
122
|
# @yieldparam [*args, &block] args, original callback
|
120
123
|
# @yieldreturn [optional]
|
@@ -133,12 +136,12 @@ class MockProxy
|
|
133
136
|
|
134
137
|
# @private
|
135
138
|
# @param [MockProxy] proxy existing proxy
|
136
|
-
# @param [String, Array<String>] key_path the chain of methods or key path. Can be a
|
139
|
+
# @param [String, Symbol, #to_s, Array<String, Symbol, #to_s>] key_path the chain of methods or key path. Can be a
|
137
140
|
# dot delimited key path or an array of method names as strings or symbols
|
138
141
|
# @return [Proc] if proc found at key path
|
139
142
|
# @raise [ArgumentError] if proc not found or hash found at key path
|
140
143
|
def self.get_callback(proxy, key_path)
|
141
|
-
key_paths = key_path.is_a?(Array) ? key_path.map(&:to_s) :key_path.split('.')
|
144
|
+
key_paths = key_path.is_a?(Array) ? key_path.map(&:to_s) : key_path.split('.')
|
142
145
|
existing_callback_hash = proxy.instance_variable_get('@callback_hash')
|
143
146
|
callback = key_paths.reduce(existing_callback_hash) do |callback_hash, key|
|
144
147
|
if callback_hash && callback_hash[key]
|
@@ -157,13 +160,13 @@ class MockProxy
|
|
157
160
|
|
158
161
|
# @private
|
159
162
|
# @param [MockProxy] proxy existing proxy
|
160
|
-
# @param [String, Array<String>] key_path the chain of methods or key path. Can be a
|
163
|
+
# @param [String, Symbol, #to_s, Array<String, Symbol, #to_s>] key_path the chain of methods or key path. Can be a
|
161
164
|
# dot delimited key path or an array of method names as strings or symbols
|
162
165
|
# @param [Proc] proc the new proc to replace the existing proc
|
163
166
|
# @return [MockProxy] if proc existed at key path
|
164
167
|
# @raise [ArgumentError] if proc not found or hash found at key path
|
165
168
|
def self.set_callback(proxy, key_path, proc)
|
166
|
-
key_paths = key_path.is_a?(Array) ? key_path.map(&:to_s) :key_path.split('.')
|
169
|
+
key_paths = key_path.is_a?(Array) ? key_path.map(&:to_s) : key_path.to_s.split('.')
|
167
170
|
copied_callback_hash = proxy.instance_variable_get('@callback_hash').clone
|
168
171
|
key_paths.reduce(copied_callback_hash) do |callback_hash, key|
|
169
172
|
if !callback_hash || !callback_hash[key]
|
data/lib/mock_proxy/version.rb
CHANGED