delegate_matcher 0.0.3 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +3 -0
  3. data/.gitignore +3 -1
  4. data/.rubocop.yml +8 -0
  5. data/.travis.yml +7 -2
  6. data/Gemfile.lock +90 -37
  7. data/Guardfile +4 -0
  8. data/README.md +106 -98
  9. data/Rakefile +3 -1
  10. data/delegate_matcher.gemspec +17 -8
  11. data/lib/delegate_matcher/delegate.rb +79 -0
  12. data/lib/delegate_matcher/delegate_matcher.rb +41 -266
  13. data/lib/delegate_matcher/delegation.rb +115 -0
  14. data/lib/delegate_matcher/dispatcher.rb +26 -0
  15. data/lib/delegate_matcher/expected.rb +108 -0
  16. data/lib/delegate_matcher/nil_delegate.rb +41 -0
  17. data/lib/delegate_matcher/stub_delegate.rb +26 -0
  18. data/lib/delegate_matcher/version.rb +1 -1
  19. data/lib/delegate_matcher.rb +9 -0
  20. data/spec/lib/active_support_delegation_spec.rb +24 -29
  21. data/spec/lib/aggregate_delegate_matcher_spec.rb +62 -0
  22. data/spec/lib/delegate_spec.rb +15 -0
  23. data/spec/lib/delegate_to_class_variable_spec.rb +85 -0
  24. data/spec/lib/delegate_to_constant_spec.rb +86 -0
  25. data/spec/lib/delegate_to_instance_variable_spec.rb +86 -0
  26. data/spec/lib/delegate_to_method_spec.rb +84 -0
  27. data/spec/lib/delegate_to_object_spec.rb +103 -0
  28. data/spec/lib/forwardable_delegation_spec.rb +14 -13
  29. data/spec/lib/shared/a_simple_delegator.rb +17 -0
  30. data/spec/lib/shared/args.rb +24 -0
  31. data/spec/lib/shared/args_and_a_block.rb +6 -0
  32. data/spec/lib/shared/author.rb +10 -0
  33. data/spec/lib/shared/block.rb +45 -0
  34. data/spec/lib/shared/different_method_name.rb +12 -0
  35. data/spec/lib/shared/different_return_value.rb +19 -0
  36. data/spec/lib/shared/nil_check.rb +52 -0
  37. data/spec/lib/shared/prefix.rb +16 -0
  38. data/spec/spec_helper.rb +6 -2
  39. metadata +85 -7
  40. data/spec/lib/delegate_matcher_spec.rb +0 -467
  41. data/spec/lib/version_spec.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2fc3381de7601d9699de188f3f24cfa11066f60
4
- data.tar.gz: 8fd2cd2811125dd7f82966141071776b64b155c9
3
+ metadata.gz: 70876c332f24b6734e75025e90814f096a922405
4
+ data.tar.gz: e7ba6dd00b072b61cfdd84d6be52015f4a974ddf
5
5
  SHA512:
6
- metadata.gz: 67f45287b58103aae009169440ef82e9fe3c7e042997072080b3ff27424aefbfb3644461fb9a4b7497af2d57abb9a7d1ca7d7b1c33c4a7d750a8e52961f6c9b5
7
- data.tar.gz: 8b32722dc5dd7698333045fe7ebc26331dad2f5f2491c48c3626faa6540195f0f00d8fc467a245245a555d55ab857ef0c774730b2a71e9fe846da7b55871cf7d
6
+ metadata.gz: 88355c0fecfc0e24710bc03e37f66a52ac70c72968427cc912577d30548981eae932af200b0e8d47a326dae4405de47f19fc74fce95107c97d85999ffd0d652b
7
+ data.tar.gz: cbb8a022a4701b3a1d06d674ed6fd2298313a87c59b78e76618bf37d86ead5e5fb38f52c894fb34a1099851dc174d31d5b473d3707632b3e8630d975b05b8c8a
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_RETRY: '3'
3
+ BUNDLE_JOBS: '3'
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  /.idea/
2
2
  /coverage/
3
- /pkg/
3
+ /pkg/
4
+ /tmp/
5
+ /Gemfile.lock/
data/.rubocop.yml CHANGED
@@ -21,3 +21,11 @@ Style/Semicolon:
21
21
 
22
22
  Lint/Eval:
23
23
  Enabled: false
24
+
25
+ AllCops:
26
+ Exclude:
27
+ - 'tmp/**/*'
28
+ - 'vendor/**/*'
29
+
30
+ Metrics/AbcSize:
31
+ Max: 20
data/.travis.yml CHANGED
@@ -1,7 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 2.0.0
4
+ - 2.0
5
5
  - 2.1
6
6
  - 2.2
7
- - ruby-head
7
+
8
+ before_install: bundle
9
+
10
+ branches:
11
+ only:
12
+ - master
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- delegate_matcher (0.0.3)
4
+ delegate_matcher (0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (4.2.3)
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
- coveralls (0.7.2)
19
- multi_json (~> 1.3)
20
- rest-client (= 1.6.7)
21
- simplecov (>= 0.7)
22
- term-ansicolor (= 1.2.2)
23
- thor (= 0.18.1)
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
- mime-types (2.4.3)
29
- minitest (5.7.0)
30
- multi_json (1.10.1)
31
- parser (2.2.2.6)
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
- rest-client (1.6.7)
37
- mime-types (>= 1.16)
38
- rspec (3.3.0)
39
- rspec-core (~> 3.3.0)
40
- rspec-expectations (~> 3.3.0)
41
- rspec-mocks (~> 3.3.0)
42
- rspec-core (3.3.2)
43
- rspec-support (~> 3.3.0)
44
- rspec-expectations (3.3.1)
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.3.0)
47
- rspec-its (1.1.0)
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.3.2)
94
+ rspec-mocks (3.4.0)
51
95
  diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.3.0)
53
- rspec-support (3.3.0)
54
- rubocop (0.33.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.2.5, < 3.0)
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.4)
103
+ ruby-progressbar (~> 1.7)
104
+ tins (<= 1.6.0)
60
105
  ruby-progressbar (1.7.5)
61
- simplecov (0.9.1)
106
+ shellany (0.0.1)
107
+ simplecov (0.10.0)
62
108
  docile (~> 1.1.0)
63
- multi_json (~> 1.0)
64
- simplecov-html (~> 0.8.0)
65
- simplecov-html (0.8.0)
66
- term-ansicolor (1.2.2)
67
- tins (~> 0.8)
68
- thor (0.18.1)
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 (0.13.2)
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
@@ -0,0 +1,4 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^lib/(.+)\.rb$}) { 'spec' }
3
+ watch(%r{^spec/(.+)\.rb$}) { 'spec' }
4
+ end
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
+ [![Gem Version](https://badge.fury.io/rb/delegate_matcher.png)](http://badge.fury.io/rb/delegate_matcher)
1
2
  [![Build Status](https://travis-ci.org/dwhelan/delegate_matcher.png?branch=master)](https://travis-ci.org/dwhelan/delegate_matcher)
3
+ [![Code Climate](https://codeclimate.com/github/dwhelan/delegate_matcher/badges/gpa.svg)](https://codeclimate.com/github/dwhelan/delegate_matcher)
4
+ [![Coverage Status](https://coveralls.io/repos/dwhelan/delegate_matcher/badge.svg?branch=master&service=github)](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 ```spec_helper.rb``` file:
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)) } # name => self.class.name class method
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 ```with_prefix``` method (based on Active Support ```delegate``` method) or the
60
- ```as``` method.
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 } # author_name => author.name
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
- If you expect the delegate to return ```nil``` when the delegate is ```nil``` rather than raising an error
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 ```allow_nil``` is specified.
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 a constant or an
86
- object since the matcher cannot validate ```nil``` handling in these cases.
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 ```with```
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
- By default, block delegation is only checked if ```with_a_block``` or ```without_a_block``` is specified.
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
- ### Active Support
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
- attr_accessor :author
132
-
133
- class_variable_set(:@@authors, ['Ann Rand', 'Catherine Asaro'])
134
- GENRES ||= ['Fiction', 'Science Fiction']
135
-
136
- delegate :name, to: :author
137
- delegate :name, to: :author, prefix: true
138
- delegate :name, to: :author, prefix: :writer
139
- delegate :name_with_nil_check, to: :author, allow_nil: true
140
- delegate :name_with_arg, to: :author
141
- delegate :name_with_block, to: :author
142
- delegate :count, to: :@@authors
143
- delegate :first, to: :GENRES
144
- delegate :name, to: :class, prefix: true
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
- def name_with_nil_check
153
- name
164
+ class Author
165
+ def name
166
+ 'Catherine Asaro'
167
+ end
154
168
  end
155
169
 
156
- def name_with_arg(arg)
157
- "#{arg} #{name}"
158
- end
170
+ describe Post do
171
+ let(:author) { subject.author }
159
172
 
160
- def name_with_block(&block)
161
- "#{block.call} #{name}"
162
- end
163
- end
173
+ it { expect(subject.name).to eq 'Catherine Asaro' }
164
174
 
165
- describe Post do
166
- it { should delegate(:name).to(:author) }
167
- it { should delegate(:name).to(:@author) }
168
- it { should delegate(:name_with_nil_check).to(:author).allow_nil }
169
- it { should delegate(:name).to(:author).with_prefix }
170
- it { should delegate(:name).to(:author).with_prefix(:writer) }
171
-
172
- it { should delegate(:name_with_arg).to(:author).with('Ms.') }
173
- it { should delegate(:name_with_block).to(:author).with_block }
174
- it { should delegate(:count).to(:@@authors) }
175
- it { should delegate(:first).to(:GENRES) }
176
- it { should delegate(:name).to(:class).with_prefix }
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
- extend Forwardable
197
+ class Post
198
+ extend Forwardable
190
199
 
191
- attr_accessor :author
200
+ attr_accessor :author
192
201
 
193
- def_delegator :author, :name
194
- def_delegator :author, :name, :writer
195
- def_delegator :author, :name_with_arg
196
- def_delegator :author, :name_with_block
197
- end
202
+ def initialize
203
+ @author = Author.new
204
+ end
198
205
 
199
- class Author
200
- def name
201
- 'Catherine Asaro'
206
+ def_delegator :author, :name
207
+ def_delegator :author, :name, :author_name
208
+ def_delegator :author, :name, :writer
202
209
  end
203
210
 
204
- def name_with_arg(arg)
205
- "#{arg} #{name}"
211
+ class Author
212
+ def name
213
+ 'Catherine Asaro'
214
+ end
206
215
  end
207
216
 
208
- def name_with_block(&block)
209
- "#{block.call} #{name}"
210
- end
211
- end
217
+ describe Post do
218
+ let(:author) { subject.author }
212
219
 
213
- describe Post do
214
- it { should delegate(:name).to(:author) }
215
- it { should delegate(:name).to(:@author) }
216
- it { should delegate(:writer).to(:author).as(:name) }
217
- it { should delegate(:name_with_arg).to(:author).with('Ms.') }
218
- it { should delegate(:name_with_block).to(:author).with_block }
219
- end
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
@@ -3,6 +3,8 @@ require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
- RuboCop::RakeTask.new
6
+ RuboCop::RakeTask.new do |task|
7
+ task.options << '--display-cop-names'
8
+ end
7
9
 
8
10
  task default: [:spec, :rubocop, :build]
@@ -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', '~> 4.2'
23
- gem.add_development_dependency 'bundler', '~> 1.7'
24
- gem.add_development_dependency 'coveralls', '~> 0.7'
25
- gem.add_development_dependency 'rake', '~> 10.0'
26
- gem.add_development_dependency 'rspec', '~> 3.0'
27
- gem.add_development_dependency 'rspec-its', '~> 1.1'
28
- gem.add_development_dependency 'rubocop', '~> 0.30'
29
- gem.add_development_dependency 'simplecov', '~> 0.9'
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