rspec-forward 0.3.0 → 0.3.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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +36 -22
- data/lib/rspec/forward/forward_scope_methods.rb +14 -4
- data/lib/rspec/forward/version.rb +1 -1
- data/rspec-forward.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b4f8c6e7d8124ea73c31bf830dd1ee274b381e402f9f72075d42c605705dc1e
|
4
|
+
data.tar.gz: a222768f7062e6e05cfcbe3bf8cc23914a7e5f6f5a57457a7f56f89848604791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 373959bf21c98b2788d98a10974b612c3ef0e625771329b97ba7d4097fc48f0c99a89220ec509beb135b5f3c513d0f0a90ecc1a6162f5274438791fb3fe4ad43
|
7
|
+
data.tar.gz: 9e4a8d5afa6d5d94f278e7613094ed2bf6a04f72297ca84fbf415e8e44cc29433cf3f86be3fd44bf340a485a1d664e25705589f3e35c79fd840c34c0b4054816
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,8 @@ complete: `spring stop`.
|
|
37
37
|
|
38
38
|
## Usage
|
39
39
|
|
40
|
+
### Forwarding from class method to instance of the same class
|
41
|
+
|
40
42
|
Assume you have a Method Object with `#call` method defined like this:
|
41
43
|
|
42
44
|
```ruby
|
@@ -75,42 +77,54 @@ RSpec.describe Add do
|
|
75
77
|
end
|
76
78
|
|
77
79
|
describe ".call" do
|
78
|
-
|
80
|
+
let(:klass) { described_class }
|
79
81
|
|
80
|
-
it
|
82
|
+
it "passes arguments to instance" do
|
83
|
+
expect(klass)
|
84
|
+
.to forward_to_instance(:call)
|
85
|
+
.with_2_args
|
86
|
+
end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
```
|
84
90
|
|
85
|
-
|
86
|
-
`should` syntax in RSpec, replace the above exaple with the following:
|
91
|
+
Possible calls to the matcher include the following:
|
87
92
|
|
88
93
|
```ruby
|
89
|
-
|
90
|
-
|
94
|
+
it { is_expected.to forward_to_instance(:call).with_no_args }
|
95
|
+
it { is_expected.to forward_to_instance(:call).with_1_arg }
|
96
|
+
it { is_expected.to forward_to_instance(:call).with_2_args }
|
97
|
+
it { is_expected.to forward_to_instance(:call).with_3_args }
|
98
|
+
it { is_expected.to forward_to_instance(:call).with_named(:foo, :bar) }
|
99
|
+
it { is_expected.to forward_to_instance(:call).with_1_arg_and_named(:foo) }
|
100
|
+
it { is_expected.to forward_to_instance(:call).with_2_args_and_named(:foo) }
|
101
|
+
it { is_expected.to forward_to_instance(:call).with_3_args_and_named(:foo, :bar) }
|
102
|
+
```
|
91
103
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
104
|
+
**TODO**: Explain `forward_to_instance_build(...)`
|
105
|
+
|
106
|
+
### Forwarding from method to another class
|
107
|
+
|
108
|
+
Assume you have a method which just passes all args to another class.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
class Add
|
112
|
+
def self.call(addend1, addend2)
|
113
|
+
@addend1 + @addend2
|
96
114
|
end
|
97
115
|
end
|
98
|
-
```
|
99
116
|
|
100
|
-
|
117
|
+
class Other
|
118
|
+
def add(...)
|
119
|
+
Add.call(...)
|
120
|
+
end
|
121
|
+
end
|
101
122
|
|
102
|
-
|
103
|
-
it { should forward_to_instance(:call).with_no_args }
|
104
|
-
it { should forward_to_instance(:call).with_1_arg }
|
105
|
-
it { should forward_to_instance(:call).with_2_args }
|
106
|
-
it { should forward_to_instance(:call).with_3_args }
|
107
|
-
it { should forward_to_instance(:call).with_named(:foo, :bar) }
|
108
|
-
it { should forward_to_instance(:call).with_1_arg_and_named(:foo) }
|
109
|
-
it { should forward_to_instance(:call).with_2_args_and_named(:foo) }
|
110
|
-
it { should forward_to_instance(:call).with_3_args_and_named(:foo, :bar) }
|
123
|
+
Add.call(3, 5) # => 8
|
111
124
|
```
|
125
|
+
[...]
|
112
126
|
|
113
|
-
**TODO**: Explain
|
127
|
+
**TODO**: Explain usage.
|
114
128
|
|
115
129
|
## Development
|
116
130
|
|
@@ -10,7 +10,17 @@ module ::RSpec
|
|
10
10
|
@args
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def find_actual(klass_or_instance)
|
14
|
+
if klass_or_instance.is_a? Class
|
15
|
+
klass_or_instance
|
16
|
+
else
|
17
|
+
klass_or_instance.class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches_for?(klass_or_instance)
|
22
|
+
actual = find_actual(klass_or_instance)
|
23
|
+
|
14
24
|
method_name = @expected
|
15
25
|
base_klass = format("%<method>s_scope", method: method_name.to_s).camelize
|
16
26
|
@scope_klass_name ||= format("%s::%s", actual.to_s, base_klass)
|
@@ -28,13 +38,13 @@ module ::RSpec
|
|
28
38
|
.and_return(:result)
|
29
39
|
|
30
40
|
if @kwargs.any?
|
31
|
-
result =
|
41
|
+
result = klass_or_instance.public_send(method_name, *@args, **@kwargs) == :result
|
32
42
|
|
33
43
|
expect(@scope_klass)
|
34
44
|
.to have_received(@target_method_name)
|
35
45
|
.with(*exp_args(actual), **@kwargs)
|
36
46
|
else
|
37
|
-
result =
|
47
|
+
result = klass_or_instance.public_send(method_name, *@args) == :result
|
38
48
|
|
39
49
|
expect(@scope_klass)
|
40
50
|
.to have_received(@target_method_name)
|
@@ -60,7 +70,7 @@ module ::RSpec
|
|
60
70
|
end
|
61
71
|
|
62
72
|
def self.included(base)
|
63
|
-
private :matches_for
|
73
|
+
private :matches_for?, :find_actual
|
64
74
|
end
|
65
75
|
end
|
66
76
|
end
|
data/rspec-forward.gemspec
CHANGED
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
41
41
|
spec.require_paths = ["lib"]
|
42
42
|
|
43
|
-
spec.add_runtime_dependency "rspec-mocks", "~> 3
|
43
|
+
spec.add_runtime_dependency "rspec-mocks", "~> 3"
|
44
44
|
spec.add_development_dependency "guard", "~> 2.16"
|
45
45
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
46
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-forward
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marz Drel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-mocks
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3
|
19
|
+
version: '3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3
|
26
|
+
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: guard
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|