ファクトリーガール/マシニストの工場には、テストケース中に同じファクトリ名のオブジェクトを1回だけ作成し、常に同じインスタンスを返すような設定がありますか?私は知っている、私は何かのようにすることができます:factory_girl/machinistのシングルトン工場?
def singleton name
@@singletons ||= {}
@@singletons[name] ||= Factory name
end
...
Factory.define :my_model do |m|
m.singleton_model { singleton :singleton_model }
end
しかし、多分もっと良い方法があります。
より詳細な回答、上記のより完全な説明を含むが、プラスキュウリを使用している場合の代替ソリューション: http://stackoverflow.com/questions/2015473/using-factory-girl-in-rails-with-associations-that-have-unique-constraints-gett/8343150#8343150 –