In the latest release of FactoryGirl, some syntactic methods such as Factory.create
were depreciated in favor of several others, most notably FactoryGirl.create
and the simpler create
.
However, experience shows that certain syntaxes are not always appropriate given the context.
Take for example:
FactoryGirl.define do
factory :article do
after_create {|a| a.comments << create(:comment) }
end
factory :comment do
end
end
Where Article has_many Comments, and Comments belongs_to Article. In the above factories, a.comments << create(:comment)
issues the error Comment(#nnn) expected, got FactoryGirl::Declaration::Static
. Change that line to a.comments << FactoryGirl.create(:comment)
and the error goes away.
It is not clear when one syntax should take precedence over any other form.