gsm*_*oza 15 ruby plugins ruby-on-rails fixtures
有十几个Rails插件,其目标是在测试中替换灯具.以下是我能想到的一些内容:
可能还有其他人.您更喜欢哪些插件?为什么?
我个人使用Faker定制的Factory类.这允许我创建我的工厂,并使用非静态数据填充生成的实例.
# spec/factory.rb
module Factory
def self.create_offer(options={})
Offer.create({
:code => Faker::Lorem.words(1),
:expires_on => Time.now + (rand(30) + 1).day
}.merge(options))
end
end
# spec_helper.rb
require 'faker'
require 'spec/factory'
# In the specs
@offer = Factory.create_offer(:code => 'TESTING')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4160 次 |
| 最近记录: |