Skip to content

Commit

Permalink
fix: support asserts with messages in Rspec/BeEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jan 19, 2024
1 parent 288061b commit 57f0bb1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Master (Unreleased)

- Support asserts with messages in `Rspec/BeEmpty`. ([@G-Rath])
- Add support for `assert_empty`, `assert_not_empty` and `refute_empty` to `RSpec/Rails/MinitestAssertions`. ([@ydah])
- Support correcting `*_instance_of` assertions in `RSpec/Rails/MinitestAssertions`. ([@G-Rath])
- Support correcting `*_includes` assertions in `RSpec/Rails/MinitestAssertions`. ([@G-Rath])
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/be_empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BeEmpty < Base
(send nil? :match_array (array))
(send nil? :contain_exactly)
}
$_?
)
PATTERN

Expand Down
31 changes: 31 additions & 0 deletions spec/rubocop/cop/rspec/be_empty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
RUBY
end

it 'registers an offense when ' \
'using `expect(array).to contain_exactly, "with a message"`' do
expect_offense(<<~RUBY)
expect(array).to contain_exactly, "with a message"
^^^^^^^^^^^^^^^ Use `be_empty` matchers for checking an empty array.
RUBY

expect_correction(<<~RUBY)
expect(array).to be_empty, "with a message"
RUBY
end

it 'registers an offense when using `expect(array).to match_array([])`' do
expect_offense(<<~RUBY)
expect(array).to match_array([])
Expand All @@ -23,9 +35,28 @@
RUBY
end

it 'registers an offense when ' \
'using `expect(array).to match_array([]), "with a message"`' do
expect_offense(<<~RUBY)
expect(array).to match_array([]), "with a message"
^^^^^^^^^^^^^^^ Use `be_empty` matchers for checking an empty array.
RUBY

expect_correction(<<~RUBY)
expect(array).to be_empty, "with a message"
RUBY
end

it 'does not register an offense when using `expect(array).to be_empty`' do
expect_no_offenses(<<~RUBY)
expect(array).to be_empty
RUBY
end

it 'does not register an offense when ' \
'using `expect(array).to be_empty, "with a message"`' do
expect_no_offenses(<<~RUBY)
expect(array).to be_empty, "with a message"
RUBY
end
end

0 comments on commit 57f0bb1

Please sign in to comment.