ruby-on-railsrspecfactory-botrspec-rails

How to add "config.include FactoryBot::Syntax::Methods" to rspec config block in spec_helper.rb?


If I add:

config.include FactoryBot::Syntax::Methods  

under

RSpec.configure do |config|  

and run rspec, I see this error:

/Users/perry_mac/rails_projects/mymri/spec/spec_helper.rb:21:in `block in ': uninitialized constant FactoryBot (NameError)

my gemfile.lock can be seen in this pastebin
my gemfile can be seen in this pastebin

If I omit the Rspec.configure statement, my tests all run fine. I'd like to make use of the abbreviated syntax, but am not sure what I am doing wrong here.

Note: FactoryBot was previously called FactoryGirl


Solution

  • Got it.

    This link showed me the way.

    The required addition should be made in spec/support/factory_bot.rb and it should look like this:

    # RSpec
    # spec/support/factory_bot.rb
    RSpec.configure do |config|
      config.include FactoryBot::Syntax::Methods
    end
    

    Note: FactoryBot was previously called FactoryGirl