ruby-on-rails - 困惑 - spec_helper.rb :94:in `<top (required)>' : uninitialized constant Shoulda (NameError)

标签 ruby-on-rails rspec mongoid shoulda

我正在使用 Rails 4 和 Mongoid 4 开发一个项目。我正在尝试按照 thoughtbot/shoulda-matchers 设置 Shoulda-matchers(版本 2.8.0) ,它指向另一个名为 README for 2.8.0 的自述文件.我希望使用 mongoid-rspec用于检测。

然而 我不断收到 spec_helper.rb:94:in '<top (required)>': uninitialized constant Shoulda (NameError)
我在 Gemfile 中添加了这个:关注 thoughtbot/shoulda-matchers

group :test do
  gem 'shoulda-matchers'
end

我还在spec_helper.rb中添加了(这是错误的来源) - 关注 thoughtbot/shoulda-matchers
Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end

我试过谷歌搜索,但没有直接的解决方案(或者没有直接的问题)。我加了 require: false在 Gemfile 中,关注 README for 2.8.0
group :test do
  gem 'shoulda-matchers', require: false
end

我加了 require 'shoulda/matchers'rails_helper.rb .我的“要求”顺序是这样的:
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'

默认情况下,require 'rspec/rails' 低于 require 'spec_helper'。由 README在github页面上提供,我应该放置shoulda\matcher低于'rspec/rails'。我也试过放置 require 'shoulda/matchers'顶部 require 'spec_helper'但它没有用。

我的版本:
Rails 4.2.1
Ruby 2.2.1
Mongoid ~ 4.0.0
rspec-rails ~ 3.0
mongoid-rspec ~ 2.1.0
shoulda-matchers 2.8.0

我真的很感激任何帮助。

最佳答案

从您提供的链接:

注意:新的配置语法在公开版本中尚不可用——请参阅 2.8.0 的自述文件以获取当前安装说明。

该注释来自主分支。当前版本 (2.8.0) 有一组不同的文档。令人困惑,我知道。

只需从 spec/spec_helper.rb 中删除该配置部分即可一切都应该再次成为彩虹和 unicorn 。

关于ruby-on-rails - 困惑 - spec_helper.rb :94:in `<top (required)>' : uninitialized constant Shoulda (NameError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31283837/

相关文章:

ruby-on-rails - RSpec 给我一个 LoadError

ruby-on-rails - 按条件划分的状态机事件不起作用

ruby-on-rails - 用 mongoid 重命名模型

ruby-on-rails - Rails mongodb - 在字段 :date 中设置今天的日期

ruby-on-rails - Ruby/Rails 中不需要的(元?)数据

mysql - 没有 AR 对象的 ActiveRecord 选择属性

mysql - 构建类似 MTurk 的应用程序——当每个任务的列名发生变化时如何使用数据库?

ruby-on-rails - rspec 显示错误信息

ruby-on-rails - 将 MongoDB 中的 _id 类型更改为整数是否不好?

ruby-on-rails - rails : Is there a rails trick to adding commas to large numbers?