Skip to content

Recognize stubbing of described_class in RSpec/SubjectStub #2088

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lovro-bikic
Copy link
Contributor

@lovro-bikic lovro-bikic commented May 24, 2025

This PR makes stubbing of described_class register an offense for RSpec/SubjectStub cop. I think this fits under this cop since its purpose is to prevent stubbing the system under test, and described_class is just that.

To give a production code example offense: I recently noticed a spec for a module that had a allow(described_class).to receive(:some_module_method).


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 May 24, 2025 20:21
@lovro-bikic lovro-bikic force-pushed the subject-stub-described-class branch from 47cb738 to ffddb14 Compare May 24, 2025 20:23
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.

1 participant