Skip to content

Commit

Permalink
Merge pull request #10970 from jcalvert/fix/10969
Browse files Browse the repository at this point in the history
[Fix #10969] Allow `Lint/AmbiguousBlockAssociation` `AllowedPa…
  • Loading branch information
koic committed Aug 29, 2022
2 parents 3360eac + 2aaecd6 commit a63fd6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
@@ -0,0 +1 @@
* [#10969](https://github.com/rubocop/rubocop/issues/10969): Fix a false negative for `AllowedPatterns` of `Lint/AmbiguousBlockAssociation` when using a method chain. ([@jcalvert][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/ambiguous_block_association.rb
Expand Up @@ -81,7 +81,7 @@ def ambiguous_block_association?(send_node)
def allowed_method_pattern?(node)
node.assignment? || node.operator_method? || node.method?(:[]) ||
allowed_method?(node.last_argument.method_name) ||
matches_allowed_pattern?(node.last_argument.method_name)
matches_allowed_pattern?(node.last_argument.send_node.source)
end

def message(send_node)
Expand Down
7 changes: 5 additions & 2 deletions spec/rubocop/cop/lint/ambiguous_block_association_spec.rb
Expand Up @@ -104,13 +104,16 @@
end

context 'when AllowedPatterns is enabled' do
let(:cop_config) { { 'AllowedPatterns' => [/change/] } }
let(:cop_config) { { 'AllowedPatterns' => [/change/, /receive\(.*?\)\.twice/] } }

it 'does not register an offense for an allowed method' do
expect_no_offenses(<<~RUBY)
expect { order.expire }.to change { order.events }
expect { order.expire }.to not_change { order.events }
RUBY

expect_no_offenses(<<~RUBY)
expect(order).to receive(:complete).twice { OrderCount.update! }
RUBY
end

it 'registers an offense for other methods' do
Expand Down

0 comments on commit a63fd6d

Please sign in to comment.