FactoryGirlの最新リリースでは、のようないくつかの構文上の方法は、Factory.create他のいくつか、特にFactoryGirl.createより単純なものを優先して減価償却されましたcreate。
ただし、経験上、コンテキストを考えると、特定の構文が常に適切であるとは限りません。
たとえば、次のようにします。
FactoryGirl.define do
factory :article do
after_create {|a| a.comments << create(:comment) }
end
factory :comment do
end
end
Article has_many Comments、およびCommentsbelongs_toArticle。上記の工場でa.comments << create(:comment)は、エラーを発行しますComment(#nnn) expected, got FactoryGirl::Declaration::Static。その行をに変更するa.comments << FactoryGirl.create(:comment)と、エラーはなくなります。
ある構文が他の形式よりも優先される場合は明確ではありません。