Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support asserts with messages in Rspec/BeEmpty #1784

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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