From 6adeda277ef93cd584847535176f8f14e7871ab3 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 6 Aug 2023 18:37:06 +0900 Subject: [PATCH] Mark to `Safe: false` for `RSpec/Rails/NegationBeValid` cop https://github.com/rubocop/rubocop-rspec/pull/1665#issuecomment-1664171143 --- CHANGELOG.md | 2 ++ config/default.yml | 2 ++ docs/modules/ROOT/pages/cops_rspec_rails.adoc | 11 ++++++++--- lib/rubocop/cop/rspec/rails/negation_be_valid.rb | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d606a99..93e80dd56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) diff --git a/config/default.yml b/config/default.yml index 8996dd730..944922901 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid RSpec/Rails/TravelAround: diff --git a/docs/modules/ROOT/pages/cops_rspec_rails.adoc b/docs/modules/ROOT/pages/cops_rspec_rails.adoc index 35313e5d7..a1c94e185 100644 --- a/docs/modules/ROOT/pages/cops_rspec_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rspec_rails.adoc @@ -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 -| - +| <> |=== 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) diff --git a/lib/rubocop/cop/rspec/rails/negation_be_valid.rb b/lib/rubocop/cop/rspec/rails/negation_be_valid.rb index 21ef6495d..2daa1320a 100644 --- a/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +++ b/lib/rubocop/cop/rspec/rails/negation_be_valid.rb @@ -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