【发布时间】: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