Skip to content

Comments

Add explanation why RSpec/DescribedClass autocorrection is unsafe#2096

Merged
bquorning merged 1 commit intorubocop:masterfrom
lovro-bikic:described-class-safety
Jul 27, 2025
Merged

Add explanation why RSpec/DescribedClass autocorrection is unsafe#2096
bquorning merged 1 commit intorubocop:masterfrom
lovro-bikic:described-class-safety

Conversation

@lovro-bikic
Copy link
Contributor

@lovro-bikic lovro-bikic commented Jul 25, 2025

Adds missing safety info on RSpec/DescribedClass. This cop has unsafe autocorrection.

The cop was made unsafe in 3574888. The reason for marking it as unsafe is documented in #795.


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: "<<next>>" in default/config.yml.

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

  • Set VersionChanged: "<<next>>" in config/default.yml.

@lovro-bikic lovro-bikic requested a review from a team as a code owner July 25, 2025 09:00
Comment on lines -50 to -57
# There's a known caveat with rspec-rails's `controller` helper that
# runs its block in a different context, and `described_class` is not
# available to it. `SkipBlocks` option excludes detection in all
# non-RSpec related blocks.
#
# To narrow down this setting to only a specific directory, it is
# possible to use an overriding configuration file local to that
# directory.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this up because in the generated documentation it's also above examples:
Image

Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

Thank you 👍🏼

@bquorning bquorning merged commit a0294a8 into rubocop:master Jul 27, 2025
27 checks passed
@lovro-bikic lovro-bikic deleted the described-class-safety branch July 27, 2025 14:21
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.

2 participants