Skip to content

Commit

Permalink
Merge pull request #1633 from ydah/fix-error-match-array
Browse files Browse the repository at this point in the history
Fix an error for `RSpec/MatchArray` when `match_array` with no argument
  • Loading branch information
bquorning authored Apr 25, 2023
2 parents 9805840 + 11901b5 commit 7226265
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/match_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/rspec/match_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7226265

Please # to comment.