Testing Class-Based Factory Resolution in factory_bot
This test suite examines FactoryBot’s behavior when attempting to create factory instances using class names instead of symbols. It specifically validates the error handling when factories are referenced by their actual class rather than the conventional symbol notation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/factory_bot
spec/acceptance/keyed_by_class_spec.rb
describe "finding factories keyed by class instead of symbol" do
before do
define_model("User") do
attr_accessor :name, :email
end
FactoryBot.define do
factory :user
end
end
it "doesn't find the factory" do
expect { FactoryBot.create(User) }.to(
raise_error(KeyError, /Factory not registered: User/)
)
end
end