Testing Factory Alias Configuration and Overrides in Factory Bot
This test suite validates Factory Bot’s alias functionality and attribute overrides in factory definitions. It examines how aliases are configured and how they interact with model attributes during object creation, ensuring proper handling of attribute mappings and overrides.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/factory_bot
spec/acceptance/aliases_spec.rb
describe "aliases and overrides" do
before do
FactoryBot.aliases << [/one/, "two"]
define_model("User", two: :string, one: :string)
FactoryBot.define do
factory :user do
two { "set value" }
end
end
end
subject { FactoryBot.create(:user, one: "override") }
its(:one) { should eq "override" }
its(:two) { should be_nil }
end