delegate_matcher 0.0.3 → 0.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/.bundle/config +3 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +8 -0
- data/.travis.yml +7 -2
- data/Gemfile.lock +90 -37
- data/Guardfile +4 -0
- data/README.md +106 -98
- data/Rakefile +3 -1
- data/delegate_matcher.gemspec +17 -8
- data/lib/delegate_matcher/delegate.rb +79 -0
- data/lib/delegate_matcher/delegate_matcher.rb +41 -266
- data/lib/delegate_matcher/delegation.rb +115 -0
- data/lib/delegate_matcher/dispatcher.rb +26 -0
- data/lib/delegate_matcher/expected.rb +108 -0
- data/lib/delegate_matcher/nil_delegate.rb +41 -0
- data/lib/delegate_matcher/stub_delegate.rb +26 -0
- data/lib/delegate_matcher/version.rb +1 -1
- data/lib/delegate_matcher.rb +9 -0
- data/spec/lib/active_support_delegation_spec.rb +24 -29
- data/spec/lib/aggregate_delegate_matcher_spec.rb +62 -0
- data/spec/lib/delegate_spec.rb +15 -0
- data/spec/lib/delegate_to_class_variable_spec.rb +85 -0
- data/spec/lib/delegate_to_constant_spec.rb +86 -0
- data/spec/lib/delegate_to_instance_variable_spec.rb +86 -0
- data/spec/lib/delegate_to_method_spec.rb +84 -0
- data/spec/lib/delegate_to_object_spec.rb +103 -0
- data/spec/lib/forwardable_delegation_spec.rb +14 -13
- data/spec/lib/shared/a_simple_delegator.rb +17 -0
- data/spec/lib/shared/args.rb +24 -0
- data/spec/lib/shared/args_and_a_block.rb +6 -0
- data/spec/lib/shared/author.rb +10 -0
- data/spec/lib/shared/block.rb +45 -0
- data/spec/lib/shared/different_method_name.rb +12 -0
- data/spec/lib/shared/different_return_value.rb +19 -0
- data/spec/lib/shared/nil_check.rb +52 -0
- data/spec/lib/shared/prefix.rb +16 -0
- data/spec/spec_helper.rb +6 -2
- metadata +85 -7
- data/spec/lib/delegate_matcher_spec.rb +0 -467
- data/spec/lib/version_spec.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70876c332f24b6734e75025e90814f096a922405
|
4
|
+
data.tar.gz: e7ba6dd00b072b61cfdd84d6be52015f4a974ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88355c0fecfc0e24710bc03e37f66a52ac70c72968427cc912577d30548981eae932af200b0e8d47a326dae4405de47f19fc74fce95107c97d85999ffd0d652b
|
7
|
+
data.tar.gz: cbb8a022a4701b3a1d06d674ed6fd2298313a87c59b78e76618bf37d86ead5e5fb38f52c894fb34a1099851dc174d31d5b473d3707632b3e8630d975b05b8c8a
|
data/.bundle/config
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
delegate_matcher (0.
|
4
|
+
delegate_matcher (0.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (4.2.
|
9
|
+
activesupport (4.2.5)
|
10
10
|
i18n (~> 0.7)
|
11
11
|
json (~> 1.7, >= 1.7.7)
|
12
12
|
minitest (~> 5.1)
|
@@ -15,61 +15,111 @@ GEM
|
|
15
15
|
ast (2.1.0)
|
16
16
|
astrolabe (1.3.1)
|
17
17
|
parser (~> 2.2)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
byebug (8.2.0)
|
19
|
+
coderay (1.1.0)
|
20
|
+
coveralls (0.8.9)
|
21
|
+
json (~> 1.8)
|
22
|
+
rest-client (>= 1.6.8, < 2)
|
23
|
+
simplecov (~> 0.10.0)
|
24
|
+
term-ansicolor (~> 1.3)
|
25
|
+
thor (~> 0.19.1)
|
26
|
+
tins (~> 1.6.0)
|
24
27
|
diff-lcs (1.2.5)
|
25
28
|
docile (1.1.5)
|
29
|
+
domain_name (0.5.25)
|
30
|
+
unf (>= 0.0.5, < 1.0.0)
|
31
|
+
ffi (1.9.10)
|
32
|
+
formatador (0.2.5)
|
33
|
+
guard (2.13.0)
|
34
|
+
formatador (>= 0.2.4)
|
35
|
+
listen (>= 2.7, <= 4.0)
|
36
|
+
lumberjack (~> 1.0)
|
37
|
+
nenv (~> 0.1)
|
38
|
+
notiffany (~> 0.0)
|
39
|
+
pry (>= 0.9.12)
|
40
|
+
shellany (~> 0.0)
|
41
|
+
thor (>= 0.18.1)
|
42
|
+
guard-compat (1.2.1)
|
43
|
+
guard-rspec (4.6.4)
|
44
|
+
guard (~> 2.1)
|
45
|
+
guard-compat (~> 1.1)
|
46
|
+
rspec (>= 2.99.0, < 4.0)
|
47
|
+
http-cookie (1.0.2)
|
48
|
+
domain_name (~> 0.5)
|
26
49
|
i18n (0.7.0)
|
27
50
|
json (1.8.3)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
51
|
+
listen (3.0.5)
|
52
|
+
rb-fsevent (>= 0.9.3)
|
53
|
+
rb-inotify (>= 0.9)
|
54
|
+
lumberjack (1.0.9)
|
55
|
+
method_source (0.8.2)
|
56
|
+
mime-types (2.99)
|
57
|
+
minitest (5.8.3)
|
58
|
+
nenv (0.2.0)
|
59
|
+
netrc (0.11.0)
|
60
|
+
notiffany (0.0.8)
|
61
|
+
nenv (~> 0.1)
|
62
|
+
shellany (~> 0.0)
|
63
|
+
parser (2.2.3.0)
|
32
64
|
ast (>= 1.1, < 3.0)
|
33
65
|
powerpack (0.1.1)
|
66
|
+
pry (0.10.3)
|
67
|
+
coderay (~> 1.1.0)
|
68
|
+
method_source (~> 0.8.1)
|
69
|
+
slop (~> 3.4)
|
70
|
+
pry-byebug (3.3.0)
|
71
|
+
byebug (~> 8.0)
|
72
|
+
pry (~> 0.10)
|
34
73
|
rainbow (2.0.0)
|
35
74
|
rake (10.4.2)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
75
|
+
rb-fsevent (0.9.6)
|
76
|
+
rb-inotify (0.9.5)
|
77
|
+
ffi (>= 0.5.0)
|
78
|
+
rest-client (1.8.0)
|
79
|
+
http-cookie (>= 1.0.2, < 2.0)
|
80
|
+
mime-types (>= 1.16, < 3.0)
|
81
|
+
netrc (~> 0.7)
|
82
|
+
rspec (3.4.0)
|
83
|
+
rspec-core (~> 3.4.0)
|
84
|
+
rspec-expectations (~> 3.4.0)
|
85
|
+
rspec-mocks (~> 3.4.0)
|
86
|
+
rspec-core (3.4.1)
|
87
|
+
rspec-support (~> 3.4.0)
|
88
|
+
rspec-expectations (3.4.0)
|
45
89
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-its (1.
|
90
|
+
rspec-support (~> 3.4.0)
|
91
|
+
rspec-its (1.2.0)
|
48
92
|
rspec-core (>= 3.0.0)
|
49
93
|
rspec-expectations (>= 3.0.0)
|
50
|
-
rspec-mocks (3.
|
94
|
+
rspec-mocks (3.4.0)
|
51
95
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.
|
53
|
-
rspec-support (3.
|
54
|
-
rubocop (0.
|
96
|
+
rspec-support (~> 3.4.0)
|
97
|
+
rspec-support (3.4.1)
|
98
|
+
rubocop (0.35.1)
|
55
99
|
astrolabe (~> 1.3)
|
56
|
-
parser (>= 2.2.
|
100
|
+
parser (>= 2.2.3.0, < 3.0)
|
57
101
|
powerpack (~> 0.1)
|
58
102
|
rainbow (>= 1.99.1, < 3.0)
|
59
|
-
ruby-progressbar (~> 1.
|
103
|
+
ruby-progressbar (~> 1.7)
|
104
|
+
tins (<= 1.6.0)
|
60
105
|
ruby-progressbar (1.7.5)
|
61
|
-
|
106
|
+
shellany (0.0.1)
|
107
|
+
simplecov (0.10.0)
|
62
108
|
docile (~> 1.1.0)
|
63
|
-
|
64
|
-
simplecov-html (~> 0.
|
65
|
-
simplecov-html (0.
|
66
|
-
|
67
|
-
|
68
|
-
|
109
|
+
json (~> 1.8)
|
110
|
+
simplecov-html (~> 0.10.0)
|
111
|
+
simplecov-html (0.10.0)
|
112
|
+
slop (3.6.0)
|
113
|
+
term-ansicolor (1.3.2)
|
114
|
+
tins (~> 1.0)
|
115
|
+
thor (0.19.1)
|
69
116
|
thread_safe (0.3.5)
|
70
|
-
tins (
|
117
|
+
tins (1.6.0)
|
71
118
|
tzinfo (1.2.2)
|
72
119
|
thread_safe (~> 0.1)
|
120
|
+
unf (0.1.4)
|
121
|
+
unf_ext
|
122
|
+
unf_ext (0.0.7.1)
|
73
123
|
|
74
124
|
PLATFORMS
|
75
125
|
ruby
|
@@ -79,6 +129,9 @@ DEPENDENCIES
|
|
79
129
|
bundler (~> 1.7)
|
80
130
|
coveralls (~> 0.7)
|
81
131
|
delegate_matcher!
|
132
|
+
guard (~> 2.13)
|
133
|
+
guard-rspec (~> 4.6)
|
134
|
+
pry-byebug (~> 3.3)
|
82
135
|
rake (~> 10.0)
|
83
136
|
rspec (~> 3.0)
|
84
137
|
rspec-its (~> 1.1)
|
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
[](http://badge.fury.io/rb/delegate_matcher)
|
1
2
|
[](https://travis-ci.org/dwhelan/delegate_matcher)
|
3
|
+
[](https://codeclimate.com/github/dwhelan/delegate_matcher)
|
4
|
+
[](https://coveralls.io/github/dwhelan/delegate_matcher?branch=master)
|
2
5
|
|
3
6
|
# Delegate Matcher
|
4
|
-
|
5
7
|
An RSpec matcher for validating delegation. This matcher works with delegation based on the [Forwardable](http://ruby-doc.org/stdlib-2.0.0/libdoc/forwardable/rdoc/Forwardable.html) module,
|
6
8
|
the [delegate](http://api.rubyonrails.org/classes/Module.html#method-i-delegate) method in the Active Support gem or with
|
7
9
|
simple custom delegation.
|
8
10
|
|
9
11
|
## Installation
|
10
|
-
|
11
12
|
Add this line to your application's Gemfile:
|
12
13
|
|
13
14
|
```ruby
|
@@ -26,14 +27,13 @@ Or install it yourself as:
|
|
26
27
|
$ gem install delegate_matcher
|
27
28
|
```
|
28
29
|
|
29
|
-
Then add the following to your
|
30
|
+
Then add the following to your `spec_helper.rb` file:
|
30
31
|
|
31
32
|
```ruby
|
32
33
|
require 'delegate_matcher'
|
33
34
|
```
|
34
35
|
|
35
36
|
## Usage
|
36
|
-
|
37
37
|
This matcher allows you to validate delegation to:
|
38
38
|
* instance methods
|
39
39
|
* class methods
|
@@ -45,7 +45,7 @@ This matcher allows you to validate delegation to:
|
|
45
45
|
```ruby
|
46
46
|
describe Post do
|
47
47
|
it { should delegate(:name).to(:author) } # name => author().name instance method
|
48
|
-
it { should delegate(:name).to(:class)
|
48
|
+
it { should delegate(:name).to(:class) } # name => self.class.name class method
|
49
49
|
it { should delegate(:name).to(:@author) } # name => @author.name instance variable
|
50
50
|
it { should delegate(:name).to(:@@author) } # name => @@author.name class variable
|
51
51
|
it { should delegate(:first).to(:GENRES) } # first => GENRES.first constant
|
@@ -56,21 +56,29 @@ end
|
|
56
56
|
### Delegate Method Name
|
57
57
|
|
58
58
|
If the name of the method being invoked on the delegate is different from the method being called you
|
59
|
-
can check this using the
|
60
|
-
|
59
|
+
can check this using the `with_prefix` method (based on Active Support `delegate` method) or the
|
60
|
+
`as` method.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
describe Post do
|
64
|
+
it { should delegate(:name).to(:author).with_prefix } # author_name => author.name
|
65
|
+
it { should delegate(:name).to(:author).with_prefix(:writer) } # writer_name => author.name
|
66
|
+
it { should delegate(:writer).to(:author).as(:name) } # writer => author.name
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
**Note**: if you are delegating to an object then you must provide an expicit prefix to `with_prefix`:
|
61
71
|
|
62
72
|
```ruby
|
63
73
|
describe Post do
|
64
|
-
it { should delegate(:name).to(author).with_prefix } #
|
74
|
+
it { should delegate(:name).to(author).with_prefix } # an error will be raised
|
65
75
|
it { should delegate(:name).to(author).with_prefix(:writer) } # writer_name => author.name
|
66
|
-
it { should delegate(:writer).to(author).as(:name) } # writer => author.name
|
67
76
|
end
|
68
77
|
```
|
69
78
|
|
70
79
|
### Handling Nil Delegates
|
71
|
-
|
72
|
-
|
73
|
-
then you can check this using the ```allow_nil``` method.
|
80
|
+
If you expect the delegate to return `nil` when the delegate is `nil` rather than raising an error
|
81
|
+
then you can check this using the `allow_nil` method.
|
74
82
|
|
75
83
|
```ruby
|
76
84
|
describe Post do
|
@@ -80,153 +88,154 @@ describe Post do
|
|
80
88
|
end
|
81
89
|
```
|
82
90
|
|
83
|
-
Nil handling is only checked if
|
91
|
+
Nil handling is only checked if `allow_nil` is specified.
|
84
92
|
|
85
|
-
Note that matcher will raise an error if you use this when checking delegation to
|
86
|
-
object since the matcher cannot validate
|
93
|
+
Note that the matcher will raise an error if you use this when checking delegation to an
|
94
|
+
object since the matcher cannot validate `nil` handling as it cannot gain access to the subject
|
95
|
+
reference to the object to set it `nil`.
|
87
96
|
|
88
97
|
### Arguments
|
89
|
-
|
90
|
-
If the method being delegated takes arguments you can supply them with the ```with``` method. The matcher
|
98
|
+
If the method being delegated takes arguments you can supply them with the `with` method. The matcher
|
91
99
|
will check that the provided arguments are in turn passed to the delegate.
|
92
100
|
|
93
101
|
```ruby
|
94
102
|
describe Post do
|
95
|
-
it { should delegate(:name).with('Ms.')to(:author) } # name('Ms.') => author.name('Ms.')
|
103
|
+
it { should delegate(:name).with('Ms.').to(:author) } # name('Ms.') => author.name('Ms.')
|
96
104
|
end
|
97
105
|
```
|
98
106
|
|
99
107
|
Also, in some cases the delegator might make minor changes to the arguments. While this is arguably no
|
100
|
-
longer true delegation you can still check that arguments are correctly passed by using a second
|
108
|
+
longer true delegation you can still check that arguments are correctly passed by using a second `with`
|
101
109
|
method to specify the arguments expected by the delegate.
|
102
110
|
|
103
111
|
```ruby
|
104
112
|
describe Post do
|
105
|
-
it { should delegate(:name).with('Ms.')to(author).with('Miss') } # name('Ms.') => author.name('Miss')
|
113
|
+
it { should delegate(:name).with('Ms.')to(:author).with('Miss') } # name('Ms.') => author.name('Miss')
|
106
114
|
end
|
107
115
|
```
|
108
116
|
|
109
117
|
### Blocks
|
110
|
-
|
111
|
-
You can check that a block passed is in turn passed to the delegate via the ```with_block``` method.
|
118
|
+
You can check that a block passed is in turn passed to the delegate via the `with_block` method.
|
112
119
|
|
113
120
|
```ruby
|
114
121
|
describe Post do
|
115
|
-
it { should delegate(:name).to(author).with_a_block } # name(&block) => author.name(&block)
|
116
|
-
it { should delegate(:name).to(author).with_block } # name(&block) => author.name(&block) # alias for with_a_block
|
122
|
+
it { should delegate(:name).to(author).with_a_block } # name(&block) => author().name(&block)
|
123
|
+
it { should delegate(:name).to(author).with_block } # name(&block) => author().name(&block) # alias for with_a_block
|
117
124
|
|
118
|
-
it { should delegate(:name).to(author).without_a_block } # name(&block) => author.name
|
119
|
-
it { should delegate(:name).to(author).without_block } # name(&block) => author.name # alias for without_a_block
|
125
|
+
it { should delegate(:name).to(author).without_a_block } # name(&block) => author().name
|
126
|
+
it { should delegate(:name).to(author).without_block } # name(&block) => author().name # alias for without_a_block
|
120
127
|
end
|
121
128
|
```
|
122
129
|
|
123
|
-
|
130
|
+
### Return Value
|
131
|
+
Normally the matcher will check that the value return is the same as the value
|
132
|
+
returned from the delegate. You can skip this check by using `without_return`.
|
124
133
|
|
125
|
-
|
134
|
+
```ruby
|
135
|
+
describe Post do
|
136
|
+
it { should delegate(:name).to(:author).without_return }
|
137
|
+
end
|
138
|
+
```
|
126
139
|
|
140
|
+
By default, block delegation is only checked if `with_a_block` or `without_a_block` is specified.
|
141
|
+
|
142
|
+
### Active Support
|
127
143
|
You can test delegation based on the [delegate](http://api.rubyonrails.org/classes/Module.html#method-i-delegate) method in the Active Support gem.
|
128
144
|
|
129
145
|
```ruby
|
130
|
-
class Post
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
class Author
|
148
|
-
def name
|
149
|
-
'Catherine Asaro'
|
146
|
+
class Post
|
147
|
+
attr_accessor :author
|
148
|
+
|
149
|
+
@@authors = ['Ann Rand', 'Catherine Asaro']
|
150
|
+
GENRES = ['Fiction', 'Science Fiction']
|
151
|
+
|
152
|
+
delegate :name, to: :author, allow_nil: true
|
153
|
+
delegate :name, to: :author, prefix: true
|
154
|
+
delegate :name, to: :author, prefix: :writer
|
155
|
+
delegate :name, to: :class, prefix: true
|
156
|
+
delegate :count, to: :@@authors
|
157
|
+
delegate :first, to: :GENRES
|
158
|
+
|
159
|
+
def initialize
|
160
|
+
@author = Author.new
|
161
|
+
end
|
150
162
|
end
|
151
163
|
|
152
|
-
|
153
|
-
name
|
164
|
+
class Author
|
165
|
+
def name
|
166
|
+
'Catherine Asaro'
|
167
|
+
end
|
154
168
|
end
|
155
169
|
|
156
|
-
|
157
|
-
|
158
|
-
end
|
170
|
+
describe Post do
|
171
|
+
let(:author) { subject.author }
|
159
172
|
|
160
|
-
|
161
|
-
"#{block.call} #{name}"
|
162
|
-
end
|
163
|
-
end
|
173
|
+
it { expect(subject.name).to eq 'Catherine Asaro' }
|
164
174
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
end
|
175
|
+
it { should delegate(:name).to(author) }
|
176
|
+
it { should delegate(:name).to(:@author) }
|
177
|
+
it { should delegate(:name).to(:author) }
|
178
|
+
it { should delegate(:name).to(:author).allow_nil }
|
179
|
+
it { should delegate(:name).to(:author).with_prefix }
|
180
|
+
it { should delegate(:name).to(:author).with_prefix(:writer) }
|
181
|
+
it { should delegate(:name).to(:author).with_block }
|
182
|
+
it { should delegate(:name).to(:author).with('Ms.') }
|
183
|
+
|
184
|
+
it { should delegate(:name).to(:class).with_prefix }
|
185
|
+
it { should delegate(:count).to(:@@authors) }
|
186
|
+
it { should delegate(:first).to(:GENRES) }
|
187
|
+
end
|
178
188
|
```
|
179
189
|
However, don't use the following features as they are not supported by the delegate method:
|
180
190
|
* delegation to objects
|
181
191
|
* different arguments passed to delegate
|
182
192
|
|
183
193
|
### Forwardable Module
|
184
|
-
|
185
194
|
You can test delegation based on the [Forwardable](http://ruby-doc.org/stdlib-2.0.0/libdoc/forwardable/rdoc/Forwardable.html) module.
|
186
195
|
|
187
196
|
```ruby
|
188
|
-
class Post
|
189
|
-
|
197
|
+
class Post
|
198
|
+
extend Forwardable
|
190
199
|
|
191
|
-
|
200
|
+
attr_accessor :author
|
192
201
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
def_delegator :author, :name_with_block
|
197
|
-
end
|
202
|
+
def initialize
|
203
|
+
@author = Author.new
|
204
|
+
end
|
198
205
|
|
199
|
-
|
200
|
-
|
201
|
-
|
206
|
+
def_delegator :author, :name
|
207
|
+
def_delegator :author, :name, :author_name
|
208
|
+
def_delegator :author, :name, :writer
|
202
209
|
end
|
203
210
|
|
204
|
-
|
205
|
-
|
211
|
+
class Author
|
212
|
+
def name
|
213
|
+
'Catherine Asaro'
|
214
|
+
end
|
206
215
|
end
|
207
216
|
|
208
|
-
|
209
|
-
|
210
|
-
end
|
211
|
-
end
|
217
|
+
describe Post do
|
218
|
+
let(:author) { subject.author }
|
212
219
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
+
it { expect(subject.name).to eq 'Catherine Asaro' }
|
221
|
+
|
222
|
+
it { should delegate(:name).to(author) }
|
223
|
+
it { should delegate(:name).to(:@author) }
|
224
|
+
it { should delegate(:name).to(:author) }
|
225
|
+
it { should delegate(:name).to(:author).with('Ms.') }
|
226
|
+
it { should delegate(:name).to(:author).with_block }
|
227
|
+
it { should delegate(:name).to(:author).with_prefix }
|
228
|
+
it { should delegate(:writer).to(:author).as(:name) }
|
229
|
+
end
|
220
230
|
```
|
221
231
|
However, don't use the following features as they are not supported by the Forwardable module:
|
222
|
-
* allow_nil
|
232
|
+
* `allow_nil`
|
223
233
|
* delegation to class variables
|
224
234
|
* delegation to constants
|
225
235
|
* delegation to objects
|
226
236
|
* different arguments passed to delegate
|
227
237
|
|
228
238
|
## Contributing
|
229
|
-
|
230
239
|
1. Fork it ( https://github.com/dwhelan/delegate_matcher/fork )
|
231
240
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
232
241
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
@@ -234,5 +243,4 @@ However, don't use the following features as they are not supported by the Forwa
|
|
234
243
|
5. Create a new Pull Request
|
235
244
|
|
236
245
|
## Notes
|
237
|
-
|
238
246
|
This matcher was inspired by [Alan Winograd](https://github.com/awinograd) via the gist https://gist.github.com/awinograd/6158961
|
data/Rakefile
CHANGED
data/delegate_matcher.gemspec
CHANGED
@@ -19,12 +19,21 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.test_files = gem.files.grep(%r{^spec/})
|
20
20
|
gem.require_paths = ['lib']
|
21
21
|
|
22
|
-
gem.add_development_dependency 'activesupport',
|
23
|
-
gem.add_development_dependency 'bundler',
|
24
|
-
gem.add_development_dependency 'coveralls',
|
25
|
-
gem.add_development_dependency '
|
26
|
-
gem.add_development_dependency 'rspec',
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
gem.add_development_dependency 'activesupport', '~> 4.2'
|
23
|
+
gem.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
gem.add_development_dependency 'coveralls', '~> 0.7'
|
25
|
+
gem.add_development_dependency 'guard', '~> 2.13'
|
26
|
+
gem.add_development_dependency 'guard-rspec', '~> 4.6'
|
27
|
+
|
28
|
+
if RUBY_VERSION =~ /2/
|
29
|
+
gem.add_development_dependency 'pry-byebug', '~> 3.3'
|
30
|
+
else
|
31
|
+
gem.add_development_dependency 'pry-debugger', '~> 0.2'
|
32
|
+
end
|
33
|
+
|
34
|
+
gem.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
gem.add_development_dependency 'rspec-its', '~> 1.1'
|
37
|
+
gem.add_development_dependency 'rubocop', '~> 0.30'
|
38
|
+
gem.add_development_dependency 'simplecov', '~> 0.9'
|
30
39
|
end
|