-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle unknown HTTP status codes for RSpecRails::HttpStatus
cop
#51
Handle unknown HTTP status codes for RSpecRails::HttpStatus
cop
#51
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need to register an offence, but with a different message, that doesn’t mention nil
, and do not autocorrect.
How does this spec work before correction?
I agree, it seems to be even better.
expect_offense(<<~RUBY)
it { is_expected.to have_http_status("some-custom-string") }
^^^^^^^^^^^^^^^^^^^^ Prefer `nil` over `"some-custom-string"` to describe HTTP status code.
RUBY |
I mean how does the |
Ah, I got you. That example is artificial. I have a project where |
Understood. Would it fix your case to still raise an offence but don’t autocorrect unknown string arguments? |
Yep. How should the message for this case look like? |
c5158ba
to
8ea4ef0
Compare
RSpecRails::HttpStatus
cop to ignore unexpected objectsRSpecRails::HttpStatus
cop
Actually the issue may happen with any |
Could you please take a look? @pirj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add your comments and Bad case about this case?
rubocop-rspec_rails/lib/rubocop/cop/rspec_rails/http_status.rb
Lines 12 to 59 in 8ea4ef0
# Enforces use of symbolic or numeric value to describe HTTP status. | |
# | |
# This cop inspects only `have_http_status` calls. | |
# So, this cop does not check if a method starting with `be_*` is used | |
# when setting for `EnforcedStyle: symbolic` or | |
# `EnforcedStyle: numeric`. | |
# | |
# @example `EnforcedStyle: symbolic` (default) | |
# # bad | |
# it { is_expected.to have_http_status 200 } | |
# it { is_expected.to have_http_status 404 } | |
# it { is_expected.to have_http_status "403" } | |
# | |
# # good | |
# it { is_expected.to have_http_status :ok } | |
# it { is_expected.to have_http_status :not_found } | |
# it { is_expected.to have_http_status :forbidden } | |
# it { is_expected.to have_http_status :success } | |
# it { is_expected.to have_http_status :error } | |
# | |
# @example `EnforcedStyle: numeric` | |
# # bad | |
# it { is_expected.to have_http_status :ok } | |
# it { is_expected.to have_http_status :not_found } | |
# it { is_expected.to have_http_status "forbidden" } | |
# | |
# # good | |
# it { is_expected.to have_http_status 200 } | |
# it { is_expected.to have_http_status 404 } | |
# it { is_expected.to have_http_status 403 } | |
# it { is_expected.to have_http_status :success } | |
# it { is_expected.to have_http_status :error } | |
# | |
# @example `EnforcedStyle: be_status` | |
# # bad | |
# it { is_expected.to have_http_status :ok } | |
# it { is_expected.to have_http_status :not_found } | |
# it { is_expected.to have_http_status "forbidden" } | |
# it { is_expected.to have_http_status 200 } | |
# it { is_expected.to have_http_status 404 } | |
# it { is_expected.to have_http_status "403" } | |
# | |
# # good | |
# it { is_expected.to be_ok } | |
# it { is_expected.to be_not_found } | |
# it { is_expected.to have_http_status :success } | |
# it { is_expected.to have_http_status :error } | |
# |
8ea4ef0
to
e741eab
Compare
Done. |
@ydah Could you please take a look? 🙂 I updated cop's docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Consider the following snippet
RSpecRails::HttpStatus
(configured with defaultsymbolic
style) reports this as an offense:Autocorrection looks like
have_http_status(nil)
which leads to runtime error.I expect the cop to ignore unexpected objects passed as http status code.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).