method_call_count 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
  SHA256:
3
- metadata.gz: c963a732eead900ad046e8eba20e5a322489649ecbd4efb1639c42fb43af8ea0
4
- data.tar.gz: 4432e172eb154e5dc8aab005d30d16078d739f2830c121c61e6e32db9ce569e9
3
+ metadata.gz: 34cff0ab8932a338191fa84bedff15cd9836c5fbda5e2f75206bf089896d8f5e
4
+ data.tar.gz: 3def0f097661863ebc0c27de58bd5465fcabec04203b4069a20d8d0f08cd2f64
5
5
  SHA512:
6
- metadata.gz: a8300464c216f1b57bb02c0f806dcb37258258dda55f648c67744b2932b1d7ce8445abc7827cee98b980e71c8608d35726c19708f1d3776671579d3fed2dd84f
7
- data.tar.gz: 22eb87fe34aaf3a335e03dd28bef492cc4ac5fa60fbd95891417e5c842a90aca6663f9e0d98c36665f33f4bba3284e54b059a735c768c2d88cabb7b3de57db97
6
+ metadata.gz: 5c19f8f4b7dbb987f4e758d788f129dab3e990d6f5460408f6ab480eaa1144bbd0c44dd302300d3f4ab9731a6354b5a07ac3ee43f81b6a2bed25bbb96cb3993a
7
+ data.tar.gz: 78d7ff0f7da43e5db3f385a41a623c5f4ed7dfe2bf847120574ded7abf96f0e4b1e27048a6da8b1d4e5d8429f43322507a8d6911fe7dff424ecc5d45cde77610
data/README.md CHANGED
@@ -41,11 +41,25 @@ my_object.times_called[:some_method] # returns 1
41
41
  For MethodCallCount::CallableStub
42
42
 
43
43
  ```
44
- my_stub = MethodCallCount::new
44
+ my_stub = MethodCallCount::CallableStub::new
45
45
  my_stub.call(arg: 'value')
46
46
  my_stub.called_with[:arg] # returns 'value'
47
47
  ```
48
48
 
49
+ You can stub the return by providing the value you want returned as an argument in the constructor
50
+
51
+ ```
52
+ my_stub = MethodCallCount::CallableStub::new('return_value')
53
+ my_stub.call(arg: 'value') # returns 'return_value'
54
+ ```
55
+
56
+ You could also pass a block, which CallableStub will yield the input kwargs to
57
+
58
+ ```
59
+ my_stub = MethodCallCount::CallableStub::new{|options| options[:arg]}
60
+ my_stub.call(arg: 'value') # returns 'value'
61
+ ```
62
+
49
63
  ## Development
50
64
 
51
65
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,11 +2,13 @@
2
2
 
3
3
  class MethodCallCount
4
4
  class CallableStub
5
- def initialize
5
+ def initialize(value = nil, &block)
6
+ @block = value.nil? ? block : ->(options){value}
6
7
  @called_with = {}
7
8
  end
8
9
  def call(options={})
9
10
  @called_with = options
11
+ @block&.call(options)
10
12
  end
11
13
  def called_with
12
14
  @called_with.dup
@@ -1,3 +1,3 @@
1
1
  class MethodCallCount
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -2,7 +2,7 @@ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'method_call_count/version'
4
4
 
5
- Gem::Specification.new 'method_call_count', '0.1.0' do |spec|
5
+ Gem::Specification.new 'method_call_count', '0.1.1' do |spec|
6
6
  spec.name = 'method_call_count'
7
7
  spec.version = MethodCallCount::VERSION
8
8
  spec.authors = ['Colin Horner']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_call_count
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
  - Colin Horner