我正在尝试使用 Rspec 测试 Controller 的这一部分:
@supercar = Supercar.find(params[:id])
这是我用于测试上述部分的 Controller 规范:
before (:each) do
@supercar = Factory :supercar
end
describe "show" do
it "assigns the requested supercar to the @supercar" do
get :show, :id => @supercar.id
assigns(:supercar).should == @supercar
end
...
但是,我尝试运行命令 rake db:migrate
,但仍然出现此错误:
Failure/Error: @supercar = Factory :supercar
ActiveRecord::StatementInvalid:
Could not find table 'supercar'
最佳答案
解决方案是运行这个命令:
rake db:test:prepare
它正在准备测试数据库,通过在那里加载方案。
关于ruby-on-rails - RSpec 错误 : test couldn't find table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19884017/