Factory Girl Blocking Rake Database Migrations
- John Wang
I use a couple of items for doing Behavior Driven Development. Primarily, Cucumber and RSpec. In conjunction with those, I use Factory Girl and Shoulda.
Sometimes, it seems that Factory Girl can get in the way of running rake db:migrate
when you push your code up to your source control system, in my case GitHub, for others download and run it. Such was the case with the Jenkins CI server.
The Issue
The problem was that Factory Girl attempts to create factories for models that did not have database tables created yet. It was trying to run before the database migrations ran when the server tried running the rake db:migrate
. (Note, yes, we always prepend bundle exec
, but shortened it here for context.)
The Solution
It seems that you're not to load the factory_girl_rails
gem in your Gemfile in the :development
group at all. The configuration on the GitHub repo just says to add it to your Gemfile, but instead you should add it to your :test
group only. For example:
gem 'factory_girl_rails', :group => :test
More details can be found on the mailing list topic.