Search code examples
ruby-on-railstestingrspecbddrspec-rails

RSpec error: test couldn't find table


I am trying to test this part of controller with Rspec:

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

Here is my controller spec to test the part mentioned above:

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
...

However, I've tried to run command rake db:migrate, but still getting this error:

Failure/Error: @supercar = Factory :supercar
     ActiveRecord::StatementInvalid:
       Could not find table 'supercar'

Solution

  • The solution is to run this command:

    rake db:test:prepare
    

    It is preparing the test database, by loading the scheme there.