【问题标题】:Rails / Factory Girl: Uninitialized constant FactoryGirl (NameError)Rails / Factory Girl:未初始化的常量 FactoryGirl (NameError)
【发布时间】:2014-12-18 11:31:52
【问题描述】:

我安装了factory_girl gem,但在运行测试时出现错误:

`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 项目吗?
  • 谢谢乔,我的问题已经解决了

标签: ruby-on-rails rspec factory-bot rspec-rails


【解决方案1】:

spec/spec_helper.rb,尝试添加

FactoryGirl.find_definitions

require 'factory_girl_rails'

或确保您遵循factory_bot's Getting Started 指南。

【讨论】:

    【解决方案2】:

    这一定是你的答案。

    需要在spec/support/factory_girl.rb中添加

    https://stackoverflow.com/a/25649064/1503970

    【讨论】:

      【解决方案3】:

      我只是把这个放在这里给像我这样笨拙的人。一切都很好,但我在一个地方打电话给FactoryGirl,当时我只安装了FactoryBot。新手错误。希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-15
        • 2017-07-10
        • 1970-01-01
        • 2022-01-01
        相关资源
        最近更新 更多