[英]Guard + Zeus + Rspec-Rails: undefined method 'configure' for Rspec:Module
我正在使用以下内容:
Rails 4.1.1
guard-zeus 2.0.0
rspec-rails 3.0.1
开箱即用的默认rails g rspec:install
和guard init
当我运行guard
并保存规范文件时,出现错误:
undefined method `configure` for RSpec:Module (NoMethodError)
我可以使用rspec spec
和rake
运行规范。
在spec_helper
,如果我require 'rspec/rails
在 configure 块之前使用require 'rspec/rails
,guard 工作正常,但是rspec spec
失败并出现错误:
uninitialized constant ActiveSupport::Autoload (NameError)
我猜现在rails_helper
和spec_helper
是分开的,加载顺序有问题。
两个问题:
你只需要回答一个问题。
以下修复对我有用:
#spec/spec_helper.rb
require 'rspec/core'
抛出一个可能是问题的快速答案。 您的 spec_helper 文件应具有以下顺序:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
在 config/environment require 之后需要需要 rspec/rails。
下列:
undefined method `configure` for RSpec:Module (NoMethodError)
表明你缺少一个
require 'rspec'
这通常不是必需的,但如果你把它放在你的spec/spec_helper.rb
中应该可以工作。
(如果您直接运行 RSpec,它已经包含在 RSpec 中)。
不包括在内的原因可能是:
你不是通过捆绑器来保护
或者您的 Gemfile 没有:
gem 'rspec' # without the require: false
或者你的.rspec
文件可能有问题(应该存在)
require 'rspec/rails'
可能应该进入spec/rails_helper.rb
...
...但更好的方法是更新您的 rspec-rails gem 并运行:
rails generate rspec:install
如果系统提示您 - 使用 'd' 表示差异(最好使用推荐的更改)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.