Search code examples
ruby-on-railsrakedatabase-schemafactory-bot

Why Factory Girl initialized during rake db:schema:load


I've upgraded from Rails 3.2 to Rails 4.1.12 and I got an error message running

rake db:drop db:create db:schema:load RAILS_ENV=test

The error message is an SQL error caused by Factory Girl with missing tables. But why is Factory Girl initialized on db:schema:load at all?

It is interesting that if I downgrade to Rails 4.1.11, the problem disappears.


Solution

  • The default behavior of the FactoryGirl gem requires it. This is the reason why it gets initialized.

    You can alter this behavior by changing the gem definition to:

    gem 'factory_girl_rails', :require => false
    

    You will then have to require it in your spec_helper.rb:

    require 'factory_girl_rails'