Skip to content

Remove RSpec/DescribedClass cop disables in specs#21608

Merged
MikeMcQuaid merged 3 commits intomainfrom
cleanup/remove-rspec-described-class-disables
Feb 22, 2026
Merged

Remove RSpec/DescribedClass cop disables in specs#21608
MikeMcQuaid merged 3 commits intomainfrom
cleanup/remove-rspec-described-class-disables

Conversation

@dduugg
Copy link
Copy Markdown
Member

@dduugg dduugg commented Feb 22, 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?
  • Have you written new 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.

AI (Cursor with Claude) was used to identify and apply idiomatic RSpec patterns. Changes were verified by running brew lgtm (typecheck, style, and all changed tests pass).


Summary

Resolves all rubocop:disable RSpec/DescribedClass comments in the test suite using idiomatic RSpec approaches:

  • free_port_spec.rb: Instead of include-ing the mixin into the example group (which conflicted with both Sorbet and RuboCop), tests the module via Object.new.extend(described_class).
  • virtualenv_spec.rb: Captures described_class in a local variable before entering the formula DSL block, where described_class is unavailable since Class.new(::Formula, &block) changes self.

Use idiomatic RSpec patterns to avoid needing `rubocop:disable`
for `RSpec/DescribedClass`:

- `free_port_spec.rb`: Test the mixin via
  `Object.new.extend(described_class)` instead of `include`-ing
  the module into the example group.
- `virtualenv_spec.rb`: Capture `described_class` in a local
  variable before the `formula` DSL block so the closure carries
  it into the class scope where `described_class` is unavailable.
@dduugg dduugg marked this pull request as ready for review February 22, 2026 04:36
Copilot AI review requested due to automatic review settings February 22, 2026 04:36
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.

Pull request overview

This PR removes all rubocop:disable RSpec/DescribedClass comments from the test suite by applying idiomatic RSpec patterns for testing modules. The changes ensure that tests properly reference the class or module being tested using described_class without triggering RuboCop violations or Sorbet conflicts.

Changes:

  • Replaced include Homebrew::FreePort with Object.new.extend(described_class) pattern for testing the FreePort module
  • Captured described_class in a local variable before the formula DSL block in virtualenv tests to maintain reference to the module being tested

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/test/free_port_spec.rb Uses Object.new.extend(described_class) with a subject to test the FreePort module without including it in the example group
Library/Homebrew/test/language/python/virtualenv_spec.rb Captures described_class in a local variable before entering the formula block where described_class is unavailable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

Nice, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Feb 22, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 22, 2026
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Feb 22, 2026
Merged via the queue into main with commit 85d148a Feb 22, 2026
37 checks passed
@MikeMcQuaid MikeMcQuaid deleted the cleanup/remove-rspec-described-class-disables branch February 22, 2026 10:53
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.

3 participants