Skip to content

Configuration and Adapters

Ngan Pham edited this page May 6, 2026 · 2 revisions

Configuration and Adapters

Use configuration to set fixture locations, cache locations, adapter behavior, callback hooks, and registered coders.

Basic Configuration

FixtureKit.configure do |config|
  config.fixture_path = Rails.root.join("spec/fixture_kit").to_s
  config.cache_path = Rails.root.join("tmp/cache/fixture_kit").to_s

  config.adapter(FixtureKit::RSpecAdapter)
end

Adapter Concept

Adapters isolate fixture generation inside framework-specific execution flow.

  • FixtureKit::RSpecAdapter executes generation in an internal RSpec example.
  • FixtureKit::MinitestAdapter executes generation in an internal ActiveSupport::TestCase test.

Custom adapters should subclass FixtureKit::Adapter.

Coders

A Coder decides what gets cached during fixture generation and how to replay it on mount. By default, FixtureKit::ActiveRecordCoder is registered and captures all ActiveRecord writes inside FixtureKit.define { ... }.

Register additional coders to capture state outside ActiveRecord — Redis, Rails.cache, ActiveStorage blobs, etc.:

FixtureKit.configure do |config|
  config.register(MyApp::RailsCacheCoder)
end

Each registered coder owns its own slice of the cache file and runs alongside the others on every save/mount. See Coders for the full contract, examples, and chain semantics.

Foreign Key Verification

When ActiveRecord.verify_foreign_keys_for_fixtures is true (default since Rails 8.0 load_defaults), FixtureKit validates foreign keys after every mount. A violation raises FixtureKit::Error with a hint that the cache may be stale relative to your current schema. See Troubleshooting if you hit one.

Canonical Signatures and Defaults

For exact method signatures, defaults, callback contracts, and errors, use the canonical in-repo reference:

Clone this wiki locally