Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix a false positive for `RspecRails/NegationBeValid` when use `to_not`. ([@ydah])

## 2.32.0 (2025-11-12)

- Add `RSpecRails/HttpStatusNameConsistency` cop. ([@taketo1113])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec_rails/negation_be_valid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NegationBeValid < ::RuboCop::Cop::Base

# @!method not_to?(node)
def_node_matcher :not_to?, <<~PATTERN
(send ... :not_to (send nil? :be_valid ...))
(send ... {:not_to :to_not} (send nil? :be_valid ...))
PATTERN

# @!method be_invalid?(node)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rspec_rails/negation_be_valid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
RUBY
end

it 'registers an offense when using ' \
'`expect(...).to_not be_valid`' do
expect_offense(<<~RUBY)
expect(foo).to_not be_valid
^^^^^^^^^^^^^^^ Use `expect(...).to be_invalid`.
RUBY
end

it 'does not register an offense when using ' \
'`expect(...).to be_invalid`' do
expect_no_offenses(<<~RUBY)
Expand Down