Testing Child-Before-Parent Factory Definitions in Factory Bot
This test suite examines FactoryBot’s capability to handle child factory definitions that precede their parent factory definitions. It validates the flexibility of factory inheritance and demonstrates how FactoryBot maintains proper relationships between parent and child factories regardless of their definition order.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/factory_bot
spec/acceptance/define_child_before_parent_spec.rb
describe "defining a child factory before a parent" do
before do
define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
FactoryBot.define do
factory :admin, parent: :user do
admin { true }
end
factory :user do
name { "awesome" }
end
end
end
it "creates admin factories correctly" do
expect(FactoryBot.create(:admin)).to be_admin
end
end