Sorbet now understands RSpec's expect block form#22329
Merged
Merged
Conversation
- The rspec-mocks gem RBI defines `ExpectHost#expect(target)` with a
required positional argument and no block, which wins over the
rspec-expectations signature via `RSpec::Core::ExampleGroup`'s include
chain. Hence, the block form `expect { ... }` — required by
matchers like `raise_error`, `output`, `change` and `yield_*` — fails
Sorbet typechecking at `# typed: true` or stricter with "Not enough
arguments provided for method
`RSpec::Mocks::ExampleMethods::ExpectHost#expect"`.
- So, add a shim that overrides `ExpectHost#expect` with the
optional-value, block-accepting signature so both `expect(value)` and
`expect { ... }` typecheck cleanly.
- Code changes made with assistance from Copilot CLI, agent mode, model
Claude Opus 4.7.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Sorbet RBI shim so expect { ... } block form typechecks against rspec-mocks' ExpectHost#expect definition, and bumps many test specs from # typed: false to # typed: true/strict now that they typecheck cleanly.
Changes:
- Override
RSpec::Mocks::ExampleMethods::ExpectHost#expectwith an optional-arg, block-accepting signature. - Promote 41 test files'
# typed:sigils totrueorstrict.
Show a summary per file
| File | Description |
|---|---|
| Library/Homebrew/sorbet/rbi/shims/rspec.rbi | Adds shim overriding ExpectHost#expect to accept block form. |
| Library/Homebrew/test/**/*_spec.rb (40 files) | Bumps # typed: false → true/strict (and one true → strict). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Files not reviewed (1)
- Library/Homebrew/sorbet/rbi/shims/rspec.rbi: Language not supported
- Files reviewed: 41/42 changed files
- Comments generated: 0
ZhongRuoyu
approved these changes
May 18, 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?Code changes made and commit message drafted with assistance from Copilot CLI, agent mode, model Claude Opus 4.7.
The rspec-mocks gem RBI defines
ExpectHost#expect(target)with a required positional argument and no block, which wins over the rspec-expectations signature viaRSpec::Core::ExampleGroup's include chain. Hence, the block formexpect { ... }— required by matchers likeraise_error,output,changeandyield_*— fails Sorbet typechecking at# typed: trueor stricter with "Not enough arguments provided for methodRSpec::Mocks::ExampleMethods::ExpectHost#expect".So, add a shim that overrides
ExpectHost#expectwith the optional-value, block-accepting signature so bothexpect(value)andexpect { ... }typecheck cleanly.With this shim,
brew tc --update --suggest-typedbumps 41 additional test files to have at least basic typechecking.