Skip to content

Commit 7226265

Browse files
authored
Merge pull request #1633 from ydah/fix-error-match-array
Fix an error for `RSpec/MatchArray` when `match_array` with no argument
2 parents 9805840 + 11901b5 commit 7226265

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix a false positive in `RSpec/IndexedLet` with suffixes after index-like numbers. ([@pirj])
66
- Fix an error for `RSpec/Rails/HaveHttpStatus` with comparison with strings containing non-numeric characters. ([@ydah])
7+
- Fix an error for `RSpec/MatchArray` when `match_array` with no argument. ([@ydah])
78

89
## 2.20.0 (2023-04-18)
910

lib/rubocop/cop/rspec/match_array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MatchArray < Base
3434
PATTERN
3535

3636
def on_send(node)
37-
return unless node.first_argument.array_type?
37+
return unless node.first_argument&.array_type?
3838
return if match_array_with_empty_array?(node)
3939

4040
check_populated_array(node)

spec/rubocop/cop/rspec/match_array_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@
4848
it { is_expected.to match_array([]) }
4949
RUBY
5050
end
51+
52+
it 'does not flag `match_array` with no argument' do
53+
expect_no_offenses(<<-RUBY)
54+
it { is_expected.to match_array }
55+
it { is_expected.to match_array() }
56+
RUBY
57+
end
5158
end

0 commit comments

Comments
 (0)