How to add "config.include FactoryBot::Syntax::Methods" to rspec config block in spec_helper.rb?
Solution 1
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
Solution 2
You must add this string in file 'spec/RAILS_helper.rb' not in 'spec_helper.rb'
Solution 3
Also make sure to require 'factory_bot'
in spec/support/factory_bot.rb
That's what ended up being the issue for me.
Solution 4
Make sure to include require 'support/factory_girl'
in spec/rails_helper.rb
after require 'rspec/rails'
.
I was getting this error after putting it right after require 'spec_helper'
.
Perry Horwich
When it comes to education, knowing the answers is probably less important than knowing the questions. Yet, I suppose, the best way to know the questions is to struggle with finding the answers. Furious activity is a poor substitute for understanding, but it can't hurt to run a few tests. Profile pic link. #SOreadytohelp
Updated on June 21, 2022Comments
-
Perry Horwich almost 2 years
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 pastebinIf 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