Skip to content

Comments

Don't register RSpec/DescribedClass offenses within Data.define blocks#2098

Merged
pirj merged 1 commit intorubocop:masterfrom
lovro-bikic:described-class-data-define
Jul 30, 2025
Merged

Don't register RSpec/DescribedClass offenses within Data.define blocks#2098
pirj merged 1 commit intorubocop:masterfrom
lovro-bikic:described-class-data-define

Conversation

@lovro-bikic
Copy link
Contributor

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

Fixes #2086.

Changes RSpec/DescribedClass so it doesn't register offenses within a Data.define block. Previously, this:

RSpec.describe Demo do
  let(:data) { Data.define(:foo) { include Demo } }
end

would have been an offense (with autocorrection to include described_class, which would raise an error because described_class isn't available within that block). With the patch, this code no longer produces an offense.


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 29, 2025 19:55
Copy link
Member

@ydah ydah 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!

@pirj pirj merged commit 027d385 into rubocop:master Jul 30, 2025
27 checks passed
@pirj
Copy link
Member

pirj commented Jul 30, 2025

Thank you!

@lovro-bikic lovro-bikic deleted the described-class-data-define branch July 30, 2025 07:49
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.

Fix RSpec/DescribedClass false positive for Data objects

3 participants