Skip to content

sorbet: Handle before blocks using let values from within tests#22480

Merged
issyl0 merged 1 commit into
mainfrom
sorbet-doesnt-understand-before-using-let-values-from-tests
May 31, 2026
Merged

sorbet: Handle before blocks using let values from within tests#22480
issyl0 merged 1 commit into
mainfrom
sorbet-doesnt-understand-before-using-let-values-from-tests

Conversation

@issyl0
Copy link
Copy Markdown
Member

@issyl0 issyl0 commented May 31, 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.

OpenAI GPT-5.3 Codex for finding all occurrences of this pattern that upset Sorbet, with local review and testing.


  • Enable typechecking of tests where a top-level before or subject block references a value that is only defined via let in tests, which Sorbet cannot resolve statically.
  • The actual value of the let that matters for the test and its setup is set in the individual tests, which will always override the top-level let value that we set.

@issyl0 issyl0 force-pushed the sorbet-doesnt-understand-before-using-let-values-from-tests branch from f1624e2 to ce6866a Compare May 31, 2026 13:53
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.

Thanks, looks good when 🟢!

@issyl0 issyl0 marked this pull request as ready for review May 31, 2026 14:05
Copilot AI review requested due to automatic review settings May 31, 2026 14:05
@issyl0 issyl0 enabled auto-merge May 31, 2026 14:05
@github-code-quality
Copy link
Copy Markdown

github-code-quality Bot commented May 31, 2026

Code Coverage Overview

Languages: Ruby

Ruby / code-coverage/simplecov

The overall coverage in the branch is 75%. The coverage in the branch is 78%.

Show a code coverage summary of the most impacted files.
File 9e7331e 8862004 +/-
cask/info.rb 96% 0% -96%
cask/installer.rb 91% 28% -63%
cask/artifact/a...ct_uninstall.rb 89% 32% -57%
cask/audit.rb 63% 25% -38%
cask/cask_loader.rb 96% 65% -31%
bundle/extensions/flatpak.rb 37% 94% +57%
extend/os/linux/diagnostic.rb 0% 67% +67%
os/linux/elf.rb 0% 86% +86%
extend/os/linux/sandbox.rb 0% 95% +95%
extend/os/linux...ystem_config.rb 0% 99% +99%

Updated May 31, 2026 14:52 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

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 aims to improve Sorbet typechecking for RSpec tests where before/subject blocks reference values that are only defined via let in nested examples (which Sorbet can’t always resolve statically).

Changes:

  • Switch a few test files from # typed: false to # typed: true.
  • Add top-level placeholder let values (e.g., who_output, string, required_ruby_version, languages) so Sorbet can resolve references from before/subject.
  • Add old_tap/new_tap and tap let values in some specs to make referenced methods visible to Sorbet.
Show a summary per file
File Description
Library/Homebrew/test/utils/user_spec.rb Enables typechecking (typed: true) and adds a placeholder let(:who_output) referenced by a before stub.
Library/Homebrew/test/utils/string_inreplace_extension_spec.rb Enables typechecking (typed: true) and adds a placeholder let(:string) used by subject.
Library/Homebrew/test/utils/ruby_check_version_script_spec.rb Enables typechecking (typed: true) and adds a placeholder let(:required_ruby_version) used by subject.
Library/Homebrew/test/formulary_spec.rb Adds top-level let(:old_tap)/let(:new_tap) for tap-migration setup used in an outer before.
Library/Homebrew/test/cmd/untap_spec.rb Adds let(:tap) inside shared examples for installed formula/cask tests.
Library/Homebrew/test/cask/dsl_spec.rb Adds a placeholder let(:languages) referenced by a before that configures cask.config.languages.

Copilot's findings

Tip

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

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread Library/Homebrew/test/cmd/untap_spec.rb Outdated
Comment thread Library/Homebrew/test/cmd/untap_spec.rb Outdated
- Enable typechecking of tests where a top-level `before` or `subject`
  block references a value that is only defined via `let` in tests,
  which Sorbet cannot resolve statically.
- The actual value of the `let` that matters for the test and its setup
  is set in the individual tests, which will always override the
  top-level `let` value that we set.
@issyl0 issyl0 force-pushed the sorbet-doesnt-understand-before-using-let-values-from-tests branch from ce6866a to 8862004 Compare May 31, 2026 14:35
@issyl0 issyl0 added this pull request to the merge queue May 31, 2026
Merged via the queue into main with commit 9f9a1a9 May 31, 2026
38 checks passed
@issyl0 issyl0 deleted the sorbet-doesnt-understand-before-using-let-values-from-tests branch May 31, 2026 16:15
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