Add on_register callback and bump to 0.18.0#72
Merged
Conversation
Adds a callback that fires when a fixture is registered (declared), before any caching. The block receives the fixture Event and the declaring scope (the example group for the RSpec adapter), enabling tooling to map a declaration back to its originating spec file via scope.metadata[:file_path]. The declaring scope is not derivable from the fixture: named fixtures are shared across scopes and store only their name string, so the scope is only known at the register(name, scope) call site. The scope rides alongside the Event as a second argument, mirroring how duration accompanies the Event for on_cache_saved/on_cache_mounted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6ts71bokStreee58rP3or
CI installs frozen against the appraisal gemfiles and the dummy app, so the tracked lockfiles must match the bumped gemspec version. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6ts71bokStreee58rP3or
Match the existing callback docs, which name the FixtureKit::Event block argument `fixture` throughout. Reverts the incidental `event` rename and the shared Event-methods note back to the established convention. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6ts71bokStreee58rP3or
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.
What
Adds a new
on_registercallback that fires when a fixture is registered (declared), before any caching::registerevent inCallbacks::EVENTS, exposed viaConfiguration#on_register.Runner#register(the single registration entry point both the RSpec and Minitest adapters go through) asrun(:register, Event.new(fixture), scope).scoperides alongside theEventas a second argument, mirroring howdurationaccompanies the Event foron_cache_saved/on_cache_mounted.Eventitself is unchanged.docs/reference.md.Why the scope is a separate argument (not read off the fixture)
The declaring scope is not derivable from the
Fixture:identifier, not a scope.Fixtureinstance can be declared in many groups — sofixture → scopeisn't even a function (see the existingspec/unit/fixture_registry_spec.rb"reuses the same named fixture instance across different scopes").definition.pathfor a named fixture points at the fixture definition file (spec/fixture_kit/<name>.rb), not the declaring spec.The scope is only known at the
register(name, scope)call site, which is where the hook fires.Motivation
Lets tooling map a fixture declaration back to its originating spec file (
scope.metadata[:file_path]for RSpec) at load time, without scanningRSpec.worldor monkeypatching the DSL. First consumer: the Buildkite RSpec formatter, to flag which spec-file folds use FixtureKit.Tests
configuration_spec—on_registerregisters/runs callbacks with the event and scope.fixture_runner_spec—registerfireson_registerwith the fixture Event and declaring scope.🤖 Generated with Claude Code
https://claude.ai/code/session_01L6ts71bokStreee58rP3or