Search code examples
ruby-on-railsfactory-bot

How do I use factories from FactoryBot in rails console


I am using rails console in the development environment and I want to use factories. How can I get access to them?

I have tried require "FactoryBot" which returns

1.9.3p393 :301 > require "FactoryBot"
LoadError: cannot load such file -- FactoryBot

Solution

  • To solve this problem ensure that the factory bot gem is specifed in your Gemfile similar to this

    group :development, :test do
      gem 'factory_bot_rails'
    end
    

    Then bundle install.

    This should make FactoryBot class available in the development console.

    Hope this helps.