Introducing FixtureKit: fixture-speed tests without giving up FactoryBot

Hi all :waving_hand:

I’d like to share FixtureKit, a gem we built at Gusto to make our test suite faster without asking hundreds of engineers to change how they write test setup.

The problem

Rails fixtures are fast. Data goes into the database once, and every test runs inside a transaction that rolls back. But in a large app with thousands of models and teams with varying Rails experience, keeping a clean set of YAML fixtures isn’t realistic. So teams reach for FactoryBot. It’s readable and flexible, but it costs time: every example rebuilds the same object graph through let! and before, running callbacks, validations and a lot of INSERTs over and over.

What FixtureKit does

FixtureKit lets you write setup in plain Ruby, using the factories you already have, and then caches that setup as SQL.

# spec/fixture_kit/project_management.rb
FixtureKit.define do
  owner = User.create!(name: "Alice", email: "alice@example.com")
  project = Project.create!(name: "Roadmap", owner: owner)

  expose(owner: owner, project: project)
end
RSpec.describe Project do
  fixture "project_management"

  it "loads exposed records" do
    expect(fixture.project.owner).to eq(fixture.owner)
  end
end

How it works:

  1. Generate once. The first time a fixture is needed, FixtureKit runs your definition block inside a transaction. It watches sql.active_record notifications t o find which tables were written to, reads the resulting rows back out as multi-row INSERT statements, and stores them in a file cache.
  2. Mount fast. After that, each example group that declares the fixture just replays those statements: one DELETE + INSERT batch per table, with referential integrity disabled during the load and foreign keys checked afterward. Callbacks, validations and factory traversal never run again.
  3. Transactional tests take it from there. Each example still runs in its own rolled-back transaction, the same as Rails fixtures.
  4. Familiar ergonomics. Exposed records come back as reader methods on fixture (fixture.owner). You can also define anonymous fixtures inline in a spec file , and build one fixture on top of another with extends:.

It works with both RSpec and Minitest, and requires Ruby 3.3+ and Rails 8.0+.

Results at Gusto

We added FixtureKit to our main monolith in February 2026 and have been moving spec files over since. We’re current around 87% adoption. Our CI suite grew by about 215,000 examples (485k total), and total CPU time still dropped by roughly 46 hours per build. Per example, that’s about 3× faster.

A few individual conversions from our history:

  • One spec file went from 74 minutes to 19 seconds.
  • Another spec got ~90% faster with a single fixture.

Try it

group :test do
  gem "fixture_kit"
end

I’d love to hear how this works on your suites, and any edge cases you hit. Feedback and PRs are very welcome!

3 Likes