【发布时间】:2011-05-18 20:27:52
【问题描述】:
我正在尝试在我的一项 gem 测试中使用 Model < ActiveRecord::Base,但出现以下错误
./test/model.rb:1:in `require': no such file to load -- active_record (LoadError)
如果没有这个调用,我会收到这个错误
./test/model.rb:1: 未初始化的常量 ActiveRecord (NameError)
帮助!我需要一个准系统 AR 模型来进行测试 :)
my_gem/test/model.rb
require 'active_record' # <= this fails
class Model < ActiveRecord::Base # <= I need a barebones AR model here
acts_as_flaggable
end
my_gem/test/test_acts_as_flaggable.rb
require 'helper'
require 'model'
class TestActsAsFlaggable < Test::Unit::TestCase
context "a model" do
setup do
@model = Model.new
end
should "be able to set flag" do
@model.flag[:foo] = "bar"
assert_equal "bar", @model.flag[:foo]
end
should "get default value for unset flags" do
@model = User.new
assert_equal false, @model.flag[:some_unset_flag]
end
end
end
免责声明:我对测试很陌生。这是我的第一颗宝石,我想确保我以“正确”的方式做事:)
【问题讨论】:
-
我相信你已经安装了 activerecord gem,你可以从 irb 要求它?
标签: ruby-on-rails-3 unit-testing activerecord gem shoulda