如何添加"config.include FactoryBot :: Syntax :: Methods"在spec_helper.rb中的rspec配置块? [英] How to add "config.include FactoryBot::Syntax::Methods" to rspec config block in spec_helper.rb?

查看:65
本文介绍了如何添加"config.include FactoryBot :: Syntax :: Methods"在spec_helper.rb中的rspec配置块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我添加:

config.include FactoryBot::Syntax::Methods  

RSpec.configure do |config|  

并运行rspec,我看到此错误:

and run rspec, I see this error:

/Users/perry_mac/rails_projects/mymri/spec/spec_helper.rb:21:in`block 在:未初始化的常量FactoryBot(NameError)

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

我的gemfile.lock可以在此pastebin
中看到 我的gemfile可以在此pastebin

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

如果我省略Rspec.configure语句,则我的测试都可以正常运行.我想使用缩写语法,但不确定在这里我做错了什么.

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.

注意:FactoryBot以前称为FactoryGirl

Note: FactoryBot was previously called FactoryGirl

推荐答案

知道了.

链接为我指明了方式.

必需的添加应在spec/support/factory_bot.rb中进行,并且应如下所示:

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

注意:FactoryBot以前称为FactoryGirl

Note: FactoryBot was previously called FactoryGirl

这篇关于如何添加"config.include FactoryBot :: Syntax :: Methods"在spec_helper.rb中的rspec配置块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆