Rails / Factory Girl: 未初始化常量 FactoryGirl (NameError)

3
我安装了factory_girl宝石,当我运行我的测试时,我得到一个错误:

`block in ': 未初始化常量 FactoryGirl (NameError)

这是我的spec_helper.rb文件:

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end

如何修复它?

你能复制你的Gemfile中的任何相关条目吗?这是你完整的spec_helper.rb吗?这是一个Rails项目吗? - Joe Ferris
谢谢你,乔。问题已经解决了。 - vveare138
3个回答

4
spec/spec_helper.rb 文件中,尝试添加以下内容。
FactoryGirl.find_definitions

下面

require 'factory_girl_rails'

或者确保你遵循 factory_bot 的入门指南


1

1

我只是为那些和我一样笨拙的人放置这里。一切都很好,但我在一个地方调用了FactoryGirl,而我只安装了FactoryBot。新手错误。希望它能有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接