-
Notifications
You must be signed in to change notification settings - Fork 3
Callback Hooks
Ngan Pham edited this page Apr 7, 2026
·
4 revisions
FixtureKit supports four callback events around cache save and cache mount.
Callbacks receive a FixtureKit::Event instance as the first argument, giving you access to fixture.identifier (the String cache key) and fixture.path (the file path where the fixture definition block was defined).
FixtureKit.configure do |config|
config.on_cache_save do |fixture|
Rails.logger.info("saving #{fixture.identifier} (defined in #{fixture.path})")
end
config.on_cache_saved do |fixture, duration|
Rails.logger.info("saved #{fixture.identifier} in #{duration.round(3)}s")
end
config.on_cache_mount do |fixture|
Rails.logger.info("mounting #{fixture.identifier}")
end
config.on_cache_mounted do |fixture, duration|
Rails.logger.info("mounted #{fixture.identifier} in #{duration.round(3)}s")
end
end- You can register multiple callbacks per event.
- Callbacks execute in registration order.
-
fixtureis aFixtureKit::Eventinstance withidentifierandpath. - Duration values are elapsed seconds (
Float) for post events.
-
on_cache_save: before cache file is generated/written. -
on_cache_saved: after save, with duration. -
on_cache_mount: before cache replay begins. -
on_cache_mounted: after mount, with duration.
For canonical signatures, see docs/reference.md.