I can't seem to add “config.include FactoryGirl::Syntax::Methods” to my rspec config block in spec_helper.rb

一笑奈何 提交于 2019-12-05 01:38:27

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

Got it.

This link showed me the way.

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

# RSpec
# spec/support/factory_girl.rb
RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
end
ni_lo

Also make sure to require 'factory_bot' in spec/support/factory_bot.rb

That's what ended up being the issue for me.

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'.

I think it's worth mentioning here that, going forward, if using FactoryGirl, you will receive a deprecation message:

The factory_girl gem has been deprecated and has been replaced by factory_bot. Please switch to factory_bot as soon as possible.

Just a note for developers in the future that are trying to use FactoryGirl.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!