Skip to content

Callback Hooks

Ngan Pham edited this page Apr 7, 2026 · 4 revisions

Callback Hooks

FixtureKit supports four callback events around cache save and cache mount.

Registering Callbacks

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

Behavior

  • You can register multiple callbacks per event.
  • Callbacks execute in registration order.
  • fixture is a FixtureKit::Event instance with identifier and path.
  • Duration values are elapsed seconds (Float) for post events.

Event Semantics

  • 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.

Clone this wiki locally