Skip to content

Add on_register callback and bump to 0.18.0#72

Merged
ngan merged 3 commits into
mainfrom
np-on-register-callback
Jul 20, 2026
Merged

Add on_register callback and bump to 0.18.0#72
ngan merged 3 commits into
mainfrom
np-on-register-callback

Conversation

@ngan

@ngan ngan commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

What

Adds a new on_register callback that fires when a fixture is registered (declared), before any caching:

config.on_register do |event, scope|
  # event: FixtureKit::Event (the declared fixture)
  # scope: the declaring context — for RSpec, the example group that called `fixture`
end
  • New :register event in Callbacks::EVENTS, exposed via Configuration#on_register.
  • Fired from Runner#register (the single registration entry point both the RSpec and Minitest adapters go through) as run(:register, Event.new(fixture), scope).
  • The scope rides alongside the Event as a second argument, mirroring how duration accompanies the Event for on_cache_saved/on_cache_mounted. Event itself is unchanged.
  • Bumps the version to 0.18.0 (additive, backward compatible).
  • Documents the callback in docs/reference.md.

Why the scope is a separate argument (not read off the fixture)

The declaring scope is not derivable from the Fixture:

  • A named fixture stores only its name string as identifier, not a scope.
  • Named fixtures are shared across scopes — one Fixture instance can be declared in many groups — so fixture → scope isn't even a function (see the existing spec/unit/fixture_registry_spec.rb "reuses the same named fixture instance across different scopes").
  • definition.path for 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 scanning RSpec.world or monkeypatching the DSL. First consumer: the Buildkite RSpec formatter, to flag which spec-file folds use FixtureKit.

Tests

  • configuration_specon_register registers/runs callbacks with the event and scope.
  • fixture_runner_specregister fires on_register with the fixture Event and declaring scope.
  • Full suite green: 185 examples, 0 failures.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6ts71bokStreee58rP3or

ngan and others added 3 commits July 19, 2026 17:04
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
@ngan
ngan merged commit 136894b into main Jul 20, 2026
13 of 14 checks passed
@ngan
ngan deleted the np-on-register-callback branch July 20, 2026 00:18
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.

1 participant