Reputation: 1795
I am reading through FactoryGirl documentation, but I didn't understand the idea of a class being guessed, what do the below comments mean?
Thanks in advance
# This will guess the User class
FactoryGirl.define do
factory :user do
first_name "Joe"
last_name "Lincol"
admin false
end
# This will use the User class (Admin would have been guessed)
factory :admin, class: User do
first_name "Admin"
last_name "User"
admin true
end
end
Upvotes: 0
Views: 35
Reputation: 9226
When deciding which class to instantiate, FactoryGirl tries to guess by using the name of the factory. In the first example, factory :user
, it will instantiate a User
class. In the second example, factory :admin
, if you don't specify the class: User
parameter, FactoryGirl would try to look for an Admin
class, which is probably not what you want.
The admin
(with true
or false
value) from the factory definitions is just a field in the User
class, it has no effect on how FactoryGirl is looking for classes to instantiate.
Upvotes: 3
Reputation: 8240
Admin is not been guessed.
The boolean flag admin true
tells that the user is an admin.
Upvotes: 1