1
我正在运行Rails 3.2.8并使用MinitTest规范进行测试。我有自动测试来管理我的测试套件,除了一件事以外,一切都很好。我有一个由ActiveRecord与MySQL管理的联系人表和一个没有数据库表的CsvImport自定义ruby类。当我在IRB中运行应用程序时,一切都按预期工作,但是当测试运行通过测试套件时,所有位于Ruby类中的Contact.find/Contact.where/Contact.map查询类型调用都返回nil。MiniTest ruby类查询返回无
下面是一个例子:
require 'test_helper'
class CsvRowManagerTest < MiniTest::Spec
describe 'import tests' do
let(:row) { Hash['name' => 'test'] }
let(:rm) { CsvRowManager.new(row) }
it "should return an array of stuff" do
rm.contacts.wont_be_nil
end
end
end
class CsvRowManager
attr_accessor :row, :contacts
def initialize(row)
@row = row
@contacts = Contact.all.map(&:name) #<-- returns nil
end
end
更多的示威比什么的。有任何想法吗?
你有没有在数据库配置文件中设置测试环境?这听起来像你有开发安装好了 – Rym
是的。它看起来像这样 测试: 适配器:sqlite3 数据库:db/test.sqlite3 – jbearden
你有样品测试吗?你有没有设置你的灯具? – Rym