In the latest version of FactoryGirl, some syntax methods, such as Factory.create
, have been discounted in favor of several others, most notably FactoryGirl.create
and the simpler create
.
However, experience has shown that some syntaxes do not always match the context.
Take for example:
FactoryGirl.define do factory :article do after_create {|a| a.comments << create(:comment) } end factory :comment do end end
If the article has_many Comments and comments belong to the article. In the above factories, a.comments << create(:comment)
throws an error Comment(#nnn) expected, got FactoryGirl::Declaration::Static
. Change this line to a.comments << FactoryGirl.create(:comment)
and the error a.comments << FactoryGirl.create(:comment)
away.
It is not clear when one syntax should take precedence over any other form.
source share