Remove RSpec/DescribedClass cop disables in specs#21608
Merged
MikeMcQuaid merged 3 commits intomainfrom Feb 22, 2026
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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::FreePortwithObject.new.extend(described_class)pattern for testing the FreePort module - Captured
described_classin 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>
MikeMcQuaid
reviewed
Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
brew lgtm(style, typechecking and tests) with your changes locally?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/DescribedClasscomments in the test suite using idiomatic RSpec approaches:free_port_spec.rb: Instead ofinclude-ing the mixin into the example group (which conflicted with both Sorbet and RuboCop), tests the module viaObject.new.extend(described_class).virtualenv_spec.rb: Capturesdescribed_classin a local variable before entering theformulaDSL block, wheredescribed_classis unavailable sinceClass.new(::Formula, &block)changesself.