我只需要信用卡和地址等属性的哈希值。 示例:
Factory.define :credit_card, :class => Object do |c|
c.first_name "Alice"
c.last_name "Liddel"
c.month "May"
c.year { Time.now.year + 1 }
c.number "1234567812345678"
c.type "Visa"
c.verification_value "123"
end
显然,对象没有任何属性,我没有credit_cord对象......我只需要一个标准的信用卡骨架。
答案 0 :(得分:1)
使用工厂女孩的优势是什么?辅助方法怎么样:
def credit_card(attrs = {})
{
:first_name => "Alice",
...,
:verification_value => "123"
}.with_indifferent_access.merge(attrs)
end
credit_card :first_name => "Linda" # returns { :first_name => "Linda", :last_name => "Liddel", ... }