-
Notifications
You must be signed in to change notification settings - Fork 0
Using Fixtures in RSpec
Ngan Pham edited this page Feb 24, 2026
·
1 revision
# spec/rails_helper.rb
require "fixture_kit/rspec"
RSpec.configure do |config|
config.use_transactional_fixtures = true
endThe RSpec entrypoint sets:
-
fixture_pathdefault tospec/fixture_kit - adapter to
FixtureKit::RSpecAdapter
RSpec.describe Project do
fixture "project_management"
it "loads data" do
expect(fixture.project).to be_present
end
endFor a group that declares fixture:
- Declaration is registered when the example group is defined.
- Cache generation runs in
prepend_before(:context)for that group. - Cache mount runs in
prepend_before(:example)and assigns repository to@_fixture_kit_repository.
Runner start (FixtureKit.runner.start) runs once in before(:suite) and clears cache path unless preserve-cache is enabled.
FixtureKit stores the declaration on group metadata key :fixture_kit_declaration.
If a spec doesn’t declare fixture and still calls fixture, FixtureKit raises:
No fixture declared for this example group. Use `fixture "name"` in your describe/context block.