Relation does not exist when running rspec tests Relation does not exist when running rspec tests ruby ruby

Relation does not exist when running rspec tests


Had this same problem and used the solution in the comment from cuvius. Posting here so that people don't miss it!

Run: RAKE_ENV=test rake db:migrate:reset db:test:prepare to set up your test database.


Unfortunately rake db:test:prepare is deprecated in rails 4+ so it's not best solution now.
I guess that in your user factory class written as User. The problem occurs because factories loads before migrations done.
So to solve this:
Change in your factory class name from

factory :user, class: User do  # ...end

to

factory :user, class: 'User' do  # ...end