我的工厂看起来像这样:
Factory.define :coupon do |c|
  c.title { Forgery(:lorem_ipsum).sentences(3, :random => true) }
end
我从Rspec打来的电话看起来像这样:
coupons = []
5.times {|i| coupons << Factory(:coupon, :starts_at => i.days.ago) }
使用我的优惠券模型,我有一个验证,要求标题是唯一的.我能够运行此测试的唯一方法是在我的工厂中执行此操作:
Factory.define :coupon do |c|
  c.title {|i| Forgery(:lorem_ipsum).sentences(3, :random => true) + "#{i}" }
end
当然必须有更好的方法吗?