mock_proxy 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f0228b892195ffaa32f34dfb387245a871bde314
4
- data.tar.gz: bbe3274ab88c596f0df31ad27544b723c5569d4a
3
+ metadata.gz: 4a0be3478b9b871a212964dcaec40e5cf40fa5ee
4
+ data.tar.gz: ae134b7b4c3c168ede44f0ba2a43316a7520e854
5
5
  SHA512:
6
- metadata.gz: c2fcbbfe5ebe19d46846c0ec49d1b959f8f40262a093050afcfa4f99ab76ff799e6fda25f4627e5206dc1e8cef3323c4fc15a58932c0aab3aed9eec0a18e2d48
7
- data.tar.gz: 9ee1cb4c96d9b808d8a328204f81e261c4da70d3b7a2872931bb4166669e0c0cb7eeeb0412a0dc1997d2714bffbda91f8ef48b171ab6e01970427ae41c4a3a44
6
+ metadata.gz: 5e95648c74a46db859ad2be919128aa33d1a57160889a575bae6c7b9ddf992d28325094b788480e9f3ef9280e37d1699fd75626064027e486377cf466b3b332c
7
+ data.tar.gz: 8dd740b3d886373d24ad3537008f8747f9379d8b96ecd79440e4e6db943c236f2c645e7858eae4801a70a3a8698c058a3e8c58a4aec105279d4f533e036d73cc
data/README.md CHANGED
@@ -57,7 +57,32 @@ Or install it yourself as:
57
57
 
58
58
  ## Usage
59
59
 
60
- TODO: Write usage instructions here
60
+ All different types of test doubles, as found on wikipedia (so you know I did my homework)
61
+ ```ruby
62
+ # Stubs
63
+ proxy = MockProxy.new(method: { chain: { ends_with: proc { |*args| return 'stuff_here' } } })
64
+ allow(object).to receive(:method).and_return proxy
65
+ run_system_under_test
66
+ # Mocks
67
+ proxy = MockProxy.new(method: { chain: { ends_with: proc { |*args| return 'stuff_here' } } })
68
+ proc = MockProxy.get(proxy, 'method.chain.ends_with')
69
+ expect(proc).to receive(:call).with('some', 'arg').twice
70
+ run_system_under_test
71
+ # Spies
72
+ called_args = []
73
+ call_count = 0
74
+ proxy = MockProxy.new(method: { chain: { ends_with: proc { |*args| called_args << args; call_count += 1 } } })
75
+ run_system_under_test
76
+ expect(call_count).to >= 1
77
+ expect(called_args).to include ['first_args', 2, 3]
78
+ # Fakes
79
+ model = double('model')
80
+ proxy = MockProxy.new(find: proc { model }, where: { first: proc { model } })
81
+ run_system_under_test
82
+ # Dummy
83
+ proxy = MockProxy.new(to_s: proc {})
84
+ run_system_under_test(proxy)
85
+ ```
61
86
 
62
87
  ## Development
63
88
 
@@ -67,7 +92,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
67
92
 
68
93
  ## Contributing
69
94
 
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mock_proxy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
95
+ Bug reports and pull requests are welcome on GitHub at https://github.com/matrinox/mock_proxy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
71
96
 
72
97
 
73
98
  ## License
@@ -44,6 +44,20 @@ require "mock_proxy/version"
44
44
  # @since 0.1.0
45
45
  #
46
46
  class MockProxy
47
+ # Retrieve the existing callback or callback tree at the specified key path
48
+ #
49
+ # NOTE: We freeze the hash so you cannot modify it
50
+ #
51
+ # Use case: Retrieve proc to mock
52
+ #
53
+ # @param [MockProxy] proxy existing proxy
54
+ # @param [String, Array<String>] key_path the chain of methods or key path. Can be a
55
+ # dot delimited key path or an array of method names as strings or symbols
56
+ # @return [Block]
57
+ def self.get(proxy, key_path)
58
+ get_callback(proxy, key_path)
59
+ end
60
+
47
61
  # Deep merges the callback tree, replacing existing values with new values
48
62
  #
49
63
  # Use case: Reuse existing stub but with some different values
@@ -165,20 +179,6 @@ class MockProxy
165
179
  end
166
180
  private_class_method :set_callback
167
181
 
168
- # Retrieve the existing callback or callback tree at the specified key path
169
- #
170
- # NOTE: We freeze the hash so you cannot modify it
171
- #
172
- # Use case: Retrieve proc to mock or retrieve hash to reflect on what is currently being stubbed
173
- #
174
- # @param [MockProxy] proxy existing proxy
175
- # @param [String, Array<String>] key_path the chain of methods or key path. Can be a
176
- # dot delimited key path or an array of method names as strings or symbols
177
- # @return [Block, Hash]
178
- def self.get(proxy, key_path)
179
-
180
- end
181
-
182
182
  # @param [Hash] callback_hash the tree of chained method calls
183
183
  def initialize(callback_hash)
184
184
  @callback_hash = callback_hash.deep_stringify_keys.freeze
@@ -1,4 +1,4 @@
1
1
  class MockProxy
2
2
  # The version number
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - matrinox