Skip to content

Move away from RSpec's described_class#22307

Open
issyl0 wants to merge 3 commits into
mainfrom
move-away-from-rspec-described-class
Open

Move away from RSpec's described_class#22307
issyl0 wants to merge 3 commits into
mainfrom
move-away-from-rspec-described-class

Conversation

@issyl0
Copy link
Copy Markdown
Member

@issyl0 issyl0 commented May 16, 2026


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes. Non-maintainers may only have one AI-assisted/generated PR open at a time.

When we moved away from using the RuboCop autocorrections for described_class replacements with class names everywhere, I used Copilot with Claude Opus 4.7 in Agent mode to make the changes in commit adf7123 to add let(:klass) { Foo } and replace described_class with klass in all the places.


Comment thread Library/Homebrew/test/bundle/flatpak_spec.rb Fixed
Comment thread Library/Homebrew/test/bundle/flatpak_spec.rb Fixed
Comment thread Library/Homebrew/test/bundle/flatpak_spec.rb Fixed
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Sorry to be that guy: now I'm actually looking at the diff, I kinda hate it 😭.

Could we do something like a type alias or e.g. test_alias = Homebrew::API::Cask::CaskStructGenerator to have RSpec handle this better with Sorbet while avoiding the excessive repetition?

@issyl0
Copy link
Copy Markdown
Member Author

issyl0 commented May 17, 2026

Sorry to be that guy: now I'm actually looking at the diff, I kinda hate it 😭.

Hah, it is quite a lot of diff.

Could we do something like a type alias or e.g. test_alias = Homebrew::API::Cask::CaskStructGenerator to have RSpec handle this better with Sorbet while avoiding the excessive repetition?

To avoid the excessive repetition let(:klass) { Homebrew::Api::Cask::CaskStructGenerator } seems to work, so we can use klass everywhere, and if the name ever changes then there's only a few places to update?

@MikeMcQuaid
Copy link
Copy Markdown
Member

To avoid the excessive repetition let(:klass) { Homebrew::Api::Cask::CaskStructGenerator } seems to work, so we can use klass everywhere, and if the name ever changes then there's only a few places to update?

Works for me!

@issyl0 issyl0 force-pushed the move-away-from-rspec-described-class branch 3 times, most recently from a04db9c to 9292fa6 Compare May 17, 2026 16:56
@issyl0 issyl0 marked this pull request as ready for review May 17, 2026 17:16
Copilot AI review requested due to automatic review settings May 17, 2026 17:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@issyl0 issyl0 force-pushed the move-away-from-rspec-described-class branch from 374e964 to 66b86b8 Compare May 17, 2026 21:07
issyl0 added 2 commits May 17, 2026 22:10
- The "explicit" setting on the `RSpec/DescribedClass` cop is still
  enabled, because `described_class` is bad for Sorbet typing, but
  instead of applying its autocorrections to specify the full class name
  everywhere that `described_class` was used, use
  `let(:klass) { Foo }` so that the repetition per-test isn't massive in
  tests that use it a lot (say, >5 times).

- Changes made with Copilot CLI, agent mode, Claude Opus 4.7.
@issyl0 issyl0 force-pushed the move-away-from-rspec-described-class branch from 66b86b8 to 461521f Compare May 17, 2026 21:11
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.

4 participants