Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 235
Perry Horwich Avatar asked Sep 03 '14 15:09

Perry Horwich


2 Answers

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

like image 108
Perry Horwich Avatar answered Oct 18 '22 11:10

Perry Horwich


You must add this string in file 'spec/RAILS_helper.rb' not in 'spec_helper.rb'

like image 11
Evgeny Palguev Avatar answered Oct 18 '22 10:10

Evgeny Palguev