0

I have a Rails app with a spec folder full of rspec tests. Many of them reference resources in my app, such as the 'User' resource. Everything is fine on my machine, but when I try to setup the app on a new machine and build the database with rake db:setup, it starts the whole Rails app, and for some reason, parts of the rspec tests get evaluated. Since one of them is referencing the 'User' resource, for which a database table has not been created yet, the rake task fails with relation "users" does not exist.

I can easily solve this my moving the spec folder out of the parent directory, running the setup, and then moving it back, but this is annoying. Obviously, I'd like for the spec files to be ignored during rake tasks like this. Any ideas?

4

1 回答 1

0

这个 SO 答案帮助了我:FactoryGirl 搞砸了 rake db:migrate process

这是对我有用的具体解决方案。

在您的 gemfile 中,更改 factory_girls_rails 所以它不是必需的

gem 'factory_girl_rails', :require => false

然后在你的规范助手中要求它

require 'factory_girl_rails'
于 2013-10-23T16:27:36.503 回答