[英]Guard + Zeus + Rspec-Rails: undefined method 'configure' for Rspec:Module
I'm using the following:我正在使用以下内容:
Rails 4.1.1
guard-zeus 2.0.0
rspec-rails 3.0.1
Out of box default rails g rspec:install
and guard init
开箱即用的默认rails g rspec:install
和guard init
When I run guard
and save a spec file, I get the error:当我运行guard
并保存规范文件时,出现错误:
undefined method `configure` for RSpec:Module (NoMethodError)
I can run specs with rspec spec
and rake
just fine.我可以使用rspec spec
和rake
运行规范。
In spec_helper
, if I require 'rspec/rails
before the configure block, guard works fine, but then rspec spec
fails with the error:在spec_helper
,如果我require 'rspec/rails
在 configure 块之前使用require 'rspec/rails
,guard 工作正常,但是rspec spec
失败并出现错误:
uninitialized constant ActiveSupport::Autoload (NameError)
I'm guessing there's a problem with load order now that rails_helper
and spec_helper
are separated.我猜现在rails_helper
和spec_helper
是分开的,加载顺序有问题。
Two questions:两个问题:
You only have to answer one question.你只需要回答一个问题。
The following fix worked for me:以下修复对我有用:
#spec/spec_helper.rb
require 'rspec/core'
Throwing out a quick answer that may be the problem.抛出一个可能是问题的快速答案。 Your spec_helper file should have the following order:您的 spec_helper 文件应具有以下顺序:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
rspec/rails needs to be required after the config/environment require.在 config/environment require 之后需要需要 rspec/rails。
The following:下列:
undefined method `configure` for RSpec:Module (NoMethodError)
suggests you are are missing a表明你缺少一个
require 'rspec'
This normally isn't necessary, but if you put it in your spec/spec_helper.rb
that should work.这通常不是必需的,但如果你把它放在你的spec/spec_helper.rb
中应该可以工作。
(If you run RSpec directly, it's included already with RSpec). (如果您直接运行 RSpec,它已经包含在 RSpec 中)。
The reason it's not included is perhaps:不包括在内的原因可能是:
you are not running guard through bundler你不是通过捆绑器来保护
or your Gemfile does not have:或者您的 Gemfile 没有:
gem 'rspec' # without the require: false
or something may be wrong with your .rspec
file (which should be present)或者你的.rspec
文件可能有问题(应该存在)
The require 'rspec/rails'
should probably go into the spec/rails_helper.rb
... require 'rspec/rails'
可能应该进入spec/rails_helper.rb
...
... but a better way would be to update your rspec-rails gem and run: ...但更好的方法是更新您的 rspec-rails gem 并运行:
rails generate rspec:install
and if you're prompted - used 'd' to differences (and ideally use the recommended changes).如果系统提示您 - 使用 'd' 表示差异(最好使用推荐的更改)。
You should add following require to top of file spec_helper.rb
您应该将以下要求添加到文件spec_helper.rb
顶部
require 'rspec/rails'
Take the reference here: Zeus GitHub issue 308参考这里: Zeus GitHub 问题 308
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.