简体   繁体   中英

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

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.

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:

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.

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).

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

require 'rspec/rails'

Take the reference here: Zeus GitHub issue 308

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM