Skip to content

Commit 540d2c9

Browse files
authored
Merge pull request #81 from rubocop/70
Fix a false positive for `RspecRails/NegationBeValid` when use `to_not`
2 parents 0ecefbc + 20929d3 commit 540d2c9

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
- Fix a false positive for `RspecRails/NegationBeValid` when use `to_not`. ([@ydah])
6+
57
## 2.32.0 (2025-11-12)
68

79
- Add `RSpecRails/HttpStatusNameConsistency` cop. ([@taketo1113])

lib/rubocop/cop/rspec_rails/negation_be_valid.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class NegationBeValid < ::RuboCop::Cop::Base
3838

3939
# @!method not_to?(node)
4040
def_node_matcher :not_to?, <<~PATTERN
41-
(send ... :not_to (send nil? :be_valid ...))
41+
(send ... {:not_to :to_not} (send nil? :be_valid ...))
4242
PATTERN
4343

4444
# @!method be_invalid?(node)

spec/rubocop/cop/rspec_rails/negation_be_valid_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
RUBY
4949
end
5050

51+
it 'registers an offense when using ' \
52+
'`expect(...).to_not be_valid`' do
53+
expect_offense(<<~RUBY)
54+
expect(foo).to_not be_valid
55+
^^^^^^^^^^^^^^^ Use `expect(...).to be_invalid`.
56+
RUBY
57+
end
58+
5159
it 'does not register an offense when using ' \
5260
'`expect(...).to be_invalid`' do
5361
expect_no_offenses(<<~RUBY)

0 commit comments

Comments
 (0)