팩토리 소녀/기계 주의자의 공장에서 테스트 케이스 중에 동일한 팩토리 이름을 가진 객체를 한 번만 생성하고 항상 같은 인스턴스를 반환하도록하는 구성이 있습니까? 알아요. 다음과 같이 할 수 있습니다.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
하지만 더 좋은 방법이있을 수 있습니다.
더 자세한 대답은, 위의 더욱 철저한 설명을 포함하여이 플러스 Cucumber를 사용하는 대체 솔루션 : http://stackoverflow.com/questions/2015473/using-factory-girl-in-rails-with-associations-that-have-unique-constraints-gett/8343150#8343150 –