[英]Confused - spec_helper.rb:94:in `<top (required)>': uninitialized constant Shoulda (NameError)
我正在开发一个带有Rails 4和Mongoid 4的项目。我正在尝试设置Shoulda- matchers (版本2.8.0),遵循thinkbot / shoulda-matchers ,它指向另一个名为README for 2.8.0的自述文件 。 我希望使用mongoid-rspec进行测试。
但是我一直得到spec_helper.rb:94:in '<top (required)>': uninitialized constant Shoulda (NameError)
我在Gemfile
添加了这个:在thinkbot / shoulda- Gemfile
之后
group :test do
gem 'shoulda-matchers'
end
我还在spec_helper.rb
添加了(错误来自哪里) - 以下thinkbot / shoulda-matchers
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
我试过谷歌搜索,但没有直接的解决方案(或者没有直接的问题)。 我在Gemfile中添加了require: false
,遵循自述文件2.8.0
group :test do
gem 'shoulda-matchers', require: false
end
我在rails_helper.rb
添加了require 'shoulda/matchers'
rails_helper.rb
require 'shoulda/matchers'
rails_helper.rb
require 'shoulda/matchers'
。 我的'要求'的顺序是这样的:
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
要求'rspec / rails'默认情况下需要'spec_helper'。 并且通过github页面上提供的README ,我应该将'should shoulda\\matcher
'放在'rspec / rails'下面。 我还尝试在require 'spec_helper'
之上放置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
删除该配置部分,所有内容应该再次为彩虹和独角兽。
只需将这些行插入spec/spec_helper.rb
:
config.include(Shoulda::Matchers::ActiveModel, type: :model)
config.include(Shoulda::Matchers::ActiveRecord, type: :model)
参考:
https://github.com/thoughtbot/shoulda-matchers#availability-of-matchers-in-various-example-groups
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.