Skip to content

Move away from RSpec's described_class#22307

Merged
MikeMcQuaid merged 3 commits into
mainfrom
move-away-from-rspec-described-class
May 22, 2026
Merged

Move away from RSpec's described_class#22307
MikeMcQuaid merged 3 commits into
mainfrom
move-away-from-rspec-described-class

Conversation

@issyl0

@issyl0 issyl0 commented May 16, 2026

Copy link
Copy Markdown
Member

  • 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

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

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

issyl0 commented May 17, 2026

Copy link
Copy Markdown
Member Author

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 2 times, most recently from 66b86b8 to 461521f Compare May 17, 2026 21:11

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good when 🟢! Don't need another review, just self-merge whenever no conflicts. Another option: do a partial merge with conflicting files removed and address conflicts in another batch to make it easier to get this landed.

Comment thread Library/Homebrew/test/api/cask/cask_struct_generator_spec.rb
@YouhuiTrading

This comment has been minimized.

issyl0 added 3 commits May 22, 2026 14:32
- 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.
- Keep specs compatible with stricter runtime checks after replacing
  `described_class` in typed tests.
- Avoid nil secrets and nil process status values tripping Sorbet runtime
  while tests exercise unauthenticated API and missing command paths.
@MikeMcQuaid MikeMcQuaid force-pushed the move-away-from-rspec-described-class branch from 461521f to 18d51e7 Compare May 22, 2026 13:39
@MikeMcQuaid MikeMcQuaid enabled auto-merge May 22, 2026 13:40
@issyl0

issyl0 commented May 22, 2026

Copy link
Copy Markdown
Member Author

Sorry, had this on my list to get back to, but then 😅🔥 - thanks for finishing it off!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 22, 2026
Merged via the queue into main with commit ba83579 May 22, 2026
96 of 102 checks passed
@MikeMcQuaid MikeMcQuaid deleted the move-away-from-rspec-described-class branch May 22, 2026 15:04
issyl0 added a commit that referenced this pull request May 25, 2026
- After #22307, I looked into what
  was needed to move the rest of the tests to Sorbet `typed: true` or
  higher.
- Running `spoom` in dry-run mode found that several files only had one
  error: using the new `klass` or `subject` variable as a dynamic
  constant, instead of the full constant name (that is,
  https://sorbet.org/docs/error-reference#5001).
- So, I got OpenAI Codex 5.3 Medium to bump all the specs to
  `typed: true`, search for only 5001 errors. There were 120 errors.
  Then for each of them I replaced `klass` or `subject` with the full
  constant name. Now a few more tests are typechecked to `true`, and
  we have less far to go on the others.
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.

5 participants