Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个这样的工厂:
FactoryGirl.define do factory :subject do name 'Calculus' end end
我想提到他的父母是“数学”,父母是空的。我该怎么做?
如果我正确理解了这个问题,您可以指定一个父级作为该factory方法的一个选项:
factory
FactoryGirl.define do factory :subject do name 'Subject' end factory :maths, :parent => :subject do name 'Maths' end factory :calculus, :parent => :maths do name 'Calculus' end end
这是一个相当人为的例子,因为子工厂覆盖了继承的name属性,但这能回答你的问题吗?
name