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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 408b6bb845882bb291901c4cdd81bdc6c0f22b90f9a28f76992e22a83c4b1c63
4
- data.tar.gz: 82a3952da4f7b3debb6759afbc0fd37340405fde5d59a3059b081d83224e9493
3
+ metadata.gz: 6b4f8c6e7d8124ea73c31bf830dd1ee274b381e402f9f72075d42c605705dc1e
4
+ data.tar.gz: a222768f7062e6e05cfcbe3bf8cc23914a7e5f6f5a57457a7f56f89848604791
5
5
  SHA512:
6
- metadata.gz: 98481a93f0e7770547c370b49d5635b0e4be146ea9b292139ca4eb692e202c1b0778410c213af863da8770d6e194aabd5212107c2c6b30061255a6e0f060ac67
7
- data.tar.gz: 403eef097334f5796c461e8bca0ad792b00e22d65d8a7484a88bab5209b59ca228fa150f8c22d4459685d1a5be93d4d16fdcf057455d7b242e56c04ccfbac4bb
6
+ metadata.gz: 373959bf21c98b2788d98a10974b612c3ef0e625771329b97ba7d4097fc48f0c99a89220ec509beb135b5f3c513d0f0a90ecc1a6162f5274438791fb3fe4ad43
7
+ data.tar.gz: 9e4a8d5afa6d5d94f278e7613094ed2bf6a04f72297ca84fbf415e8e44cc29433cf3f86be3fd44bf340a485a1d664e25705589f3e35c79fd840c34c0b4054816
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-forward (0.3.0)
5
- rspec-mocks (~> 3.9)
4
+ rspec-forward (0.3.1)
5
+ rspec-mocks (~> 3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
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
- subject { described_class }
80
+ let(:klass) { described_class }
79
81
 
80
- it { should forward_to_instance(:call).with_2_args }
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
- If you would rather not use the old, deprecated
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
- describe ".call" do
90
- let(:klass) { described_class }
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
- it "passes arguments to instance" do
93
- expect(klass)
94
- .to forward_to_instance(:call)
95
- .with_2_args
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
- Possible calls to the matcher include the following:
117
+ class Other
118
+ def add(...)
119
+ Add.call(...)
120
+ end
121
+ end
101
122
 
102
- ```ruby
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 `forward_to_instance_build(...)`
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 matches_for?(actual)
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 = actual.public_send(method_name, *@args, **@kwargs) == :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 = actual.public_send(method_name, *@args) == :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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Forward
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -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.9"
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.0
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-08-13 00:00:00.000000000 Z
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.9'
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.9'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard
29
29
  requirement: !ruby/object:Gem::Requirement