Skip to content

Conversation

alexevanczuk
Copy link
Contributor

@alexevanczuk alexevanczuk commented Oct 21, 2025

The goal of this PR is to activate RSpec typing behind a feature flag.

Specifically, it makes it so with the flag, RSpec.describe will ensure that RSpec::Core::ExampleGroup API is available in the nested it blocks.

Add support for RSpec.describe to inherit from RSpec::Core::ExampleGroup.
This allows before hooks and other test methods to access RSpec DSL methods
like expect, subject, is_expected, etc.

Based on prior work that was backed out in commit 5276b75.

Committed-By-Agent: claude
This flag controls whether RSpec.describe will be transformed to inherit
from RSpec::Core::ExampleGroup. When disabled (default), RSpec.describe
behaves like a regular describe call.

This allows users to opt-in to experimental RSpec support while keeping
the default behavior unchanged.

Committed-By-Agent: claude
The experimentalRSpecEnabled flag was being set in Options but not copied
to GlobalState, so the rewriter couldn't see it. This caused RSpec.describe
to not be recognized even when --enable-experimental-rspec was set.

Committed-By-Agent: claude
Allow RSpec.shared_examples, RSpec.shared_context, and RSpec.shared_examples_for
to be used at the top level (outside of describe blocks) when the
--enable-experimental-rspec flag is enabled.

This mirrors the RSpec.describe support and uses the same isRSpec check.

Committed-By-Agent: claude
@alexevanczuk alexevanczuk marked this pull request as ready for review October 21, 2025 19:27
@alexevanczuk alexevanczuk requested a review from a team as a code owner October 21, 2025 19:27
@alexevanczuk alexevanczuk requested review from jez and removed request for a team October 21, 2025 19:27
Copy link
Collaborator

@jez jez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we should have a CLI flag. we can continue discussion in your doc internally

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean for rspec_describe__experimental.rb and rspec_describe.rb to be typechecked in one unit?

filenames that have a __ in them are special. look for files named like __1.rb and __2.rb for more examples

We need to either:

  • rename rspec_describe.rbrspec_describe__stable.rb, or
  • rename rspec_describe__experimental.rbrspec_describe_experimental.rb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, I meant for them to be separate tests – one with the experimental flag and no type errors, and one without the flag and with errors. I'll delete this anyways since we won't ship with a flag.

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.

2 participants