Fixture-level performance without giving up FactoryBot-style test setup.
Rails fixtures are very performant. But in large companies with hundreds of models and varying Rails familiarity, maintaining a well-manicured garden of YAML files quickly becomes unrealistic.
Teams reach for tools like FactoryBot to simplify test setup and keep things readable. The tradeoff is performance. FixtureKit gives you the speed wins while letting you keep the test setup tooling your teams already use, by generating and caching fixture data on-demand.
- Full documentation (guides): GitHub Wiki
- API/reference (canonical): docs/reference.md
group :test do
gem "fixture_kit"
end# 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)
endRSpec:
# spec/rails_helper.rb
require "fixture_kit/rspec"
RSpec.configure do |config|
config.use_transactional_fixtures = true
endMinitest:
# test/test_helper.rb
require "fixture_kit/minitest"
class ActiveSupport::TestCase
self.use_transactional_tests = true
endRSpec:
RSpec.describe Project do
fixture "project_management"
it "loads exposed records" do
expect(fixture.project.owner).to eq(fixture.owner)
end
endMinitest:
class ProjectTest < ActiveSupport::TestCase
fixture "project_management"
test "loads exposed records" do
assert_equal fixture.owner, fixture.project.owner
end
endfixture returns a Repository, and exposed names become reader methods.
- Ruby >= 3.3
- ActiveRecord >= 8.0
- ActiveSupport >= 8.0
MIT. See LICENSE.