【发布时间】:2015-07-08 05:00:14
【问题描述】:
我正在使用 Rails 4 和 Mongoid 4 开发一个项目。我正在尝试在 thoughtbot/shoulda-matchers 之后设置 Shoulda-matchers(版本 2.8.0),它指向另一个名为 README for 2.8.0 的 README。我希望使用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
我试过谷歌搜索,但没有直接的解决方案(或者没有直接的问题)。我在 Gemfile 中添加了require: false,紧随README for 2.8.0
group :test do
gem 'shoulda-matchers', require: false
end
我在rails_helper.rb 中添加了require 'shoulda/matchers'。我的“要求”顺序是这样的:
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'rspec/rails' 默认低于 require 'spec_helper'。通过github页面上提供的README,我应该将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
非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails rspec mongoid shoulda