method_call_count 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/method_call_count/callable_stub.rb +3 -1
- data/lib/method_call_count/version.rb +1 -1
- data/method_call_count.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34cff0ab8932a338191fa84bedff15cd9836c5fbda5e2f75206bf089896d8f5e
|
4
|
+
data.tar.gz: 3def0f097661863ebc0c27de58bd5465fcabec04203b4069a20d8d0f08cd2f64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/method_call_count.gemspec
CHANGED
@@ -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.
|
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']
|