Skip to content
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

Add new RSpec/Rails/HaveHttpStatus cop #1307

Merged
merged 1 commit into from
Jul 1, 2022

Conversation

akiomik
Copy link
Contributor

@akiomik akiomik commented Jun 30, 2022

This cop checks that tests use have_http_status instead of equality matchers (e.g. be).

Example

# bad
expect(response.status).to be 200

# good
expect(response).to have_http_status 200

Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • Added the new cop to config/default.yml.
  • The cop is configured as Enabled: pending in config/default.yml.
  • The cop is configured as Enabled: true in .rubocop.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.
  • Set VersionAdded in default/config.yml to the next minor version.

If you have modified an existing cop's configuration options:

  • Set VersionChanged in config/default.yml to the next major version.

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Just glanced over, let me run it on real-world-rspec later today.

@akiomik akiomik force-pushed the have-http-status branch from 6cd4454 to eb40985 Compare June 30, 2022 10:59
@akiomik akiomik force-pushed the have-http-status branch from 9608f3c to b282d44 Compare July 1, 2022 14:44
@pirj pirj force-pushed the have-http-status branch from b282d44 to ef14fc2 Compare July 1, 2022 20:47
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked on real-world-rspec:

57497 files inspected, 3841 offenses detected, 3841 offenses auto-correctable

and all those thousands of offences look legit! 👏 🎉

Thank you! Fantastic contribution!

@pirj pirj force-pushed the have-http-status branch from b161070 to f05f6f8 Compare July 1, 2022 20:57
@bquorning bquorning merged commit bcde3ae into rubocop:master Jul 1, 2022
@akiomik akiomik deleted the have-http-status branch July 2, 2022 01:14
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Feb 13, 2025
…: 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants