Skip to content

Commit

Permalink
Merge pull request #1685 from rubocop/mark-unsafe-for-negation-be-valid
Browse files Browse the repository at this point in the history
Mark to `Safe: false` for `RSpec/Rails/NegationBeValid`  cop
  • Loading branch information
bquorning authored Aug 6, 2023
2 parents d66612b + 6adeda2 commit 4071f9b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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)

- Mark to `Safe: false` for `RSpec/Rails/NegationBeValid` cop. ([@ydah])

## 2.23.0 (2023-07-30)

- Add new `RSpec/Rails/NegationBeValid` cop. ([@ydah])
Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,14 @@ RSpec/Rails/MinitestAssertions:

RSpec/Rails/NegationBeValid:
Description: Enforces use of `be_invalid` or `not_to` for negated be_valid.
Safe: false
EnforcedStyle: not_to
SupportedStyles:
- not_to
- be_invalid
Enabled: pending
VersionAdded: '2.23'
VersionChanged: "<<next>>"
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid

RSpec/Rails/TravelAround:
Expand Down
11 changes: 8 additions & 3 deletions docs/modules/ROOT/pages/cops_rspec_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,19 @@ expect(b).not_to eq(a)
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| Yes
| Yes
| No
| Yes (Unsafe)
| 2.23
| -
| <<next>>
|===

Enforces use of `be_invalid` or `not_to` for negated be_valid.

=== Safety

This cop is unsafe because it cannot guarantee that
the test target is an instance of `ActiveModel::Validations``.

=== Examples

==== EnforcedStyle: not_to (default)
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/rspec/rails/negation_be_valid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module RSpec
module Rails
# Enforces use of `be_invalid` or `not_to` for negated be_valid.
#
# @safety
# This cop is unsafe because it cannot guarantee that
# the test target is an instance of `ActiveModel::Validations``.
#
# @example EnforcedStyle: not_to (default)
# # bad
# expect(foo).to be_invalid
Expand Down

0 comments on commit 4071f9b

Please sign in to comment.