Skip to content

Sorbet now understands RSpec's expect block form#22329

Merged
MikeMcQuaid merged 2 commits into
mainfrom
rspec-expect-takes-one-arg-or-a-block
May 18, 2026
Merged

Sorbet now understands RSpec's expect block form#22329
MikeMcQuaid merged 2 commits into
mainfrom
rspec-expect-takes-one-arg-or-a-block

Conversation

@issyl0
Copy link
Copy Markdown
Member

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

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 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.

  • With this shim, brew tc --update --suggest-typed bumps 41 additional test files to have at least basic typechecking.

issyl0 added 2 commits May 17, 2026 22:37
- 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.
@issyl0 issyl0 marked this pull request as ready for review May 17, 2026 22:07
Copilot AI review requested due to automatic review settings May 17, 2026 22:07
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

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#expect with an optional-arg, block-accepting signature.
  • Promote 41 test files' # typed: sigils to true or strict.
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: falsetrue/strict (and one truestrict).

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

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!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit c3542bb May 18, 2026
41 checks passed
@MikeMcQuaid MikeMcQuaid deleted the rspec-expect-takes-one-arg-or-a-block branch May 18, 2026 15:49
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.

4 participants