File tree Expand file tree Collapse file tree 5 files changed +22
-2
lines changed Expand file tree Collapse file tree 5 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 66* Fix documentation rake task to support Rubocop 0.75. ([ @nickcampbell18 ] [ ] )
77* Fix ` RSpec/SubjectStub ` to detect implicit subjects stubbed. ([ @QQism ] [ ] )
88* Fix ` RSpec/Pending ` not flagging ` skip ` with string values. ([ @pirj ] [ ] )
9+ * Add ` AllowedExplicitMatchers ` config option for ` RSpec/PredicateMatcher ` . ([ @mkrawc ] [ ] )
910
1011## 1.36.0 (2019-09-27)
1112
@@ -460,3 +461,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
460461[ @nickcampbell18 ] : https://github.com/nickcampbell18
461462[ @QQism ] : https://github.com/QQism
462463[ @kellysutton ] : https://github.com/kellysutton
464+ [ @mkrawc ] : https://github.com/mkrawc
Original file line number Diff line number Diff line change @@ -368,6 +368,7 @@ RSpec/PredicateMatcher:
368368 Enabled : true
369369 Strict : true
370370 EnforcedStyle : inflected
371+ AllowedExplicitMatchers : []
371372 SupportedStyles :
372373 - inflected
373374 - explicit
Original file line number Diff line number Diff line change @@ -138,6 +138,10 @@ module ExplicitHelper
138138
139139 private
140140
141+ def allowed_explicit_matchers
142+ cop_config . fetch ( 'AllowedExplicitMatchers' , [ ] ) + BUILT_IN_MATCHERS
143+ end
144+
141145 def check_explicit ( node ) # rubocop:disable Metrics/MethodLength
142146 predicate_matcher_block? ( node ) do |_actual , matcher |
143147 add_offense (
@@ -178,7 +182,7 @@ def check_explicit(node) # rubocop:disable Metrics/MethodLength
178182 def predicate_matcher_name? ( name )
179183 name = name . to_s
180184
181- return false if BUILT_IN_MATCHERS . include? ( name )
185+ return false if allowed_explicit_matchers . include? ( name )
182186
183187 name . start_with? ( 'be_' , 'have_' ) && !name . end_with? ( '?' )
184188 end
Original file line number Diff line number Diff line change @@ -2430,6 +2430,7 @@ Name | Default value | Configurable values
24302430--- | --- | ---
24312431Strict | ` true ` | Boolean
24322432EnforcedStyle | ` inflected ` | ` inflected ` , ` explicit `
2433+ AllowedExplicitMatchers | ` [] ` | Array
24332434
24342435### References
24352436
Original file line number Diff line number Diff line change 55
66 let ( :cop_config ) do
77 { 'EnforcedStyle' => enforced_style ,
8- 'Strict' => strict }
8+ 'Strict' => strict ,
9+ 'AllowedExplicitMatchers' => allowed_explicit_matchers }
910 end
11+ let ( :allowed_explicit_matchers ) { [ ] }
1012
1113 context 'when enforced style is `inflected`' do
1214 let ( :enforced_style ) { 'inflected' }
270272 RUBY
271273 end
272274
275+ context 'when custom matchers are allowed' do
276+ let ( :allowed_explicit_matchers ) { [ 'have_http_status' ] }
277+
278+ it 'accepts custom allowed explicit matchers' do
279+ expect_no_offenses ( <<-RUBY )
280+ expect(foo).to have_http_status(:ok)
281+ RUBY
282+ end
283+ end
284+
273285 it 'accepts non-predicate matcher' do
274286 expect_no_offenses ( <<-RUBY )
275287 expect(foo).to be(true)
You can’t perform that action at this time.
0 commit comments