Ruby Gem: Uninitialized constant FactoryBot

Bryan L. picture Bryan L. · Jan 4, 2018 · Viewed 14.4k times · Source

Working on a Ruby gem and trying to use FactoryBot inside with RSpec.

I have this in support/factory_bot.rb:

RSpec.configure do |config|
  config.include FactoryBot::Syntax::Methods

  config.before(:suite) do
    FactoryBot.find_definitions
  end
end

and in spec_helper.rb:

require 'support/factory_bot'

When I try to run the spec rake task, I get this error:

support/factory_bot.rb:2:in `block in <top (required)>': uninitialized constant FactoryBot (NameError)

What am I missing? This used to work fine when I was using the old factory_girl gem, but it has broken with the rename to factory_bot. Thanks!!

Answer

Bryan L. picture Bryan L. · Jan 4, 2018

Doh. Silly mistake here, running bundle exec rake spec instead of rake spec solved it.

Also had to add require 'factory_bot' to the top of support/factory_bot.rb