diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a8c6d96e..d094bb270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix a false positive in `RSpec/IndexedLet` with suffixes after index-like numbers. ([@pirj]) - Fix an error for `RSpec/Rails/HaveHttpStatus` with comparison with strings containing non-numeric characters. ([@ydah]) +- Fix an error for `RSpec/MatchArray` when `match_array` with no argument. ([@ydah]) ## 2.20.0 (2023-04-18) diff --git a/lib/rubocop/cop/rspec/match_array.rb b/lib/rubocop/cop/rspec/match_array.rb index 058c69f5b..b92e5f227 100644 --- a/lib/rubocop/cop/rspec/match_array.rb +++ b/lib/rubocop/cop/rspec/match_array.rb @@ -34,7 +34,7 @@ class MatchArray < Base PATTERN def on_send(node) - return unless node.first_argument.array_type? + return unless node.first_argument&.array_type? return if match_array_with_empty_array?(node) check_populated_array(node) diff --git a/spec/rubocop/cop/rspec/match_array_spec.rb b/spec/rubocop/cop/rspec/match_array_spec.rb index 840c46886..86dde2450 100644 --- a/spec/rubocop/cop/rspec/match_array_spec.rb +++ b/spec/rubocop/cop/rspec/match_array_spec.rb @@ -48,4 +48,11 @@ it { is_expected.to match_array([]) } RUBY end + + it 'does not flag `match_array` with no argument' do + expect_no_offenses(<<-RUBY) + it { is_expected.to match_array } + it { is_expected.to match_array() } + RUBY + end end