Guard + Zeus + Rspec-Rails: undefined method 'configure' for Rspec:Module

房东的猫 提交于 2019-12-11 13:36:43

问题


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

When I run guard and save a spec file, I get the error:

undefined method `configure` for RSpec:Module (NoMethodError)

I can run specs with rspec spec and rake just fine.

In spec_helper, if I require 'rspec/rails before the configure block, guard works fine, but then rspec spec fails with the error:

uninitialized constant ActiveSupport::Autoload (NameError)

I'm guessing there's a problem with load order now that rails_helper and spec_helper are separated.

Two questions:

  1. How can I fix this?
  2. Is there a different solution for continuous integration locally that you can recommend that works with latest Rails and Rspec.

You only have to answer one question.


回答1:


The following fix to me:

#spec/spec_helper.rb
require 'rspec/core'



回答2:


Throwing out a quick answer that may be the problem. Your spec_helper file should have the following order:

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.




回答3:


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.

(If you run RSpec directly, it's included already with RSpec).

The reason it's not included is perhaps:

  • you are not running guard through bundler

  • or your Gemfile does not have:

    gem 'rspec' # without the require: false
    
  • or something may be wrong with your .rspec file (which should be present)

The require 'rspec/rails' should probably go into the spec/rails_helper.rb...

... but a better way would be to update your rspec-rails gem and run:

rails generate rspec:install

and if you're prompted - used 'd' to differences (and ideally use the recommended changes).




回答4:


You should add following require to top of file spec_helper.rb

require 'rspec/rails'

Take the reference here: Zeus GitHub issue 308



来源:https://stackoverflow.com/questions/25939918/guard-zeus-rspec-rails-undefined-method-configure-for-rspecmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!