【发布时间】:2010-04-28 19:43:12
【问题描述】:
建造以下工厂时:
Factory.define :user do |f|
f.sequence(:name) { |n| "foo#{n}" }
f.resume_type_id { ResumeType.first.id }
end
ResumeType.first 返回 nil,我得到一个错误。
ResumeType 记录通过固定装置加载。我使用控制台检查并且条目在那里,表不是空的。
我在 factory_girl 邮件列表中找到了一个类似的示例,它应该可以工作。
我错过了什么?在运行测试之前,我是否必须以某种方式告诉 factory_girl 设置固定装置?
这就是我的 test_helper 的样子:
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class ActiveSupport::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
fixtures :all
end
【问题讨论】:
-
为什么要混合使用工厂和固定装置?工厂更换固定装置。
-
你的 test_helper.rb 是什么样子的?
-
我正在为固定数据使用固定数据,这些数据在播种后不会被任何人更改。
-
我在问题中添加了 test_helper.rb
-
在我的情况下,回答“为什么要混合使用工厂和固定装置”的问题?以小步骤从一个到另一个。
标签: ruby-on-rails unit-testing factory fixtures factory-bot