【问题标题】:RSpec error: test couldn't find tableRSpec 错误:测试找不到表
【发布时间】:2013-11-09 22:42:17
【问题描述】:

我正在尝试使用 Rspec 测试这部分控制器:

@supercar = Supercar.find(params[:id])

这是我用于测试上述部分的控制器规格:

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'

【问题讨论】:

  • 我很惊讶它没有在寻找表“超级跑车”。您是否在 Supercar Model 上设置了表名?
  • 工厂调用不应该像 Factory.create(:supercar) - 这看起来像旧的 FactoryGirl 语法。我已经习惯看到更像@car = FactoryGirl.create(:supercar)
  • 确保您已正确设置测试数据库:在 rake db:migrate 之后运行 rake db:test:clone

标签: ruby-on-rails testing rspec bdd rspec-rails


【解决方案1】:

解决办法是运行这个命令:

rake db:test:prepare

它正在准备测试数据库,通过在那里加载方案。

【讨论】:

    猜你喜欢
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多