Skip to content

Conversation

@lovro-bikic
Copy link
Contributor

@lovro-bikic lovro-bikic commented Nov 27, 2025

Currently, RSpec/DescribedClass won't register offenses when described class uses a constant base and the reference doesn't, and vice versa. For example:

RSpec.describe MyClass do
  before do
    MyClass.foo # RSpec/DescribedClass registers an offense
    ::MyClass.foo # RSpec/DescribedClass does not register an offense currently
  end
end

This PR adds handling of constant bases to this cop.


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).

@lovro-bikic lovro-bikic requested a review from a team as a code owner November 27, 2025 10:29
Comment on lines +53 to +56
# # good
# describe MyClass do
# subject { described_class::CONSTANT }
# end
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 added this because I think a "good" example was missing here

Comment on lines +492 to +500
it 'ignores parenthesized namespaces within modules - begin_types' do
expect_no_offenses(<<~RUBY)
module Foo
describe MyClass do
subject { (MyNamespace)::MyClass }
end
end
RUBY
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is currently failing on master

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