Conversation
940eb7f to
3f8fb92
Compare
…ple groups When shared example groups are auto-included via `config.include_context` with metadata filters, RSpec creates those child groups during configuration — before the spec file's `fixture` call sets the declaration on the parent group's metadata. Since RSpec snapshots parent metadata into child groups at creation time, the child's metadata never includes the fixture declaration, and the `prepend_before` hook never fires for those examples. The fix uses RSpec's own `update_inherited_metadata` to propagate the fixture declaration to any child groups that already exist when `fixture` is called. This is the same mechanism RSpec uses internally to push metadata updates to descendants. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3f8fb92 to
f2b8d3d
Compare
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.
Summary
Fixes a bug where
fixturedeclarations are invisible to examples inside shared example groups that are auto-included viaconfig.include_contextwith metadata filters.Root cause: When
config.include_context "shared examples", :some_metadatais configured, RSpec creates those child groups during configuration — before the spec file'sfixturecall sets the declaration on the parent group's metadata. Since RSpec snapshots parent metadata into child groups at creation time (metadata.update(parent_metadata)), the child's metadata never includes the:fixture_kit_declarationkey. Theprepend_before(:example, DECLARATION_METADATA_KEY)hook never fires for examples in those groups, leaving@_fixture_kit_repositorynil.Fix: Replace the direct
metadata[DECLARATION_METADATA_KEY] = declarationwithupdate_inherited_metadata(DECLARATION_METADATA_KEY => declaration). This is RSpec's own mechanism for pushing metadata updates — it sets the metadata on the current group AND recursively propagates to all existing children and their examples.Real-world impact: This bug affects any RSpec spec where shared examples are globally auto-included via metadata filters. For example, at Gusto, all GraphQL mutation specs auto-include authorization shared examples via
config.include_context 'applies mutation authorization correctly', :subgraph. Any mutation spec that usesfixturehits this bug.Changes
lib/fixture_kit/rspec.rb: Replace direct metadata assignment withupdate_inherited_metadatato propagate fixture declarations to already-created child groupsspec/dummy/spec/integration/fixture_kit_integration.rb: Add integration test reproducing the exact pattern — shared examples auto-included viaconfig.include_contextwith metadata, host group declaresfixturespec/integration/dummy_app_spec.rb: Add expected assertion markers for the new test (RSpec-only, since shared examples are an RSpec concept)spec/unit/rspec_entrypoint_spec.rb: Addupdate_inherited_metadatato the test stubTest plan
🤖 Generated with Claude Code