我正在使用 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-matchersShoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
我试过谷歌搜索,但没有直接的解决方案(或者没有直接的问题)。我加了
require: false
在 Gemfile 中,关注 README for 2.8.0group :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/