Skip to content

Commit

Permalink
Change RSpecRails/HaveHttpStatus from Autocorrect: false to `Safe…
Browse files Browse the repository at this point in the history
…: false`

Fixes: #5

This is because `response.status` is not always the HTTP response as commented below. I don't think this is an autocorrect is not safe. What do you think?
rubocop/rubocop-rspec#1307 (comment)
  • Loading branch information
ydah committed Feb 13, 2025
1 parent 801dfe4 commit 5547ab7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

- Handle unknown HTTP status codes for `RSpecRails/HttpStatus` cop. ([@viralpraxis])
- Change `RSpecRails/HaveHttpStatus` from `Autocorrect: false` to `Safe: false`. ([@ydah])

## 2.30.0 (2024-06-12)

Expand Down
4 changes: 2 additions & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ RSpecRails/HaveHttpStatus:
ResponseMethods:
- response
- last_response
SafeAutoCorrect: false
Safe: false
VersionAdded: '2.12'
VersionChanged: '2.27'
VersionChanged: "<<next>>"
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HaveHttpStatus

RSpecRails/HttpStatus:
Expand Down
10 changes: 8 additions & 2 deletions docs/modules/ROOT/pages/cops_rspecrails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ end
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Yes
| No
| Always (Unsafe)
| 2.12
| 2.27
| <<next>>
|===
Checks that tests use `have_http_status` instead of equality matchers.
[#safety-rspecrailshavehttpstatus]
=== Safety
This cop is marked as unsafe because
`response.status` response is not always an HTTP response.
[#examples-rspecrailshavehttpstatus]
=== Examples
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/rspec_rails/have_http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module Cop
module RSpecRails
# Checks that tests use `have_http_status` instead of equality matchers.
#
# @safety
# This cop is marked as unsafe because
# `response.status` response is not always an HTTP response.
#
# @example ResponseMethods: ['response', 'last_response'] (default)
# # bad
# expect(response.status).to be(200)
Expand Down

0 comments on commit 5547ab7

Please sign in to comment.