2

我正在使用以下内容:

Rails 4.1.1
guard-zeus 2.0.0
rspec-rails 3.0.1

开箱即用的默认值rails g rspec:installguard init

当我运行guard并保存规范文件时,出现错误:

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

我可以运行规范rspec spec并且rake很好。

spec_helper,如果我require 'rspec/rails在配置块之前,守卫工作正常,但随后rspec spec失败并出现错误:

uninitialized constant ActiveSupport::Autoload (NameError)

我猜现在加载顺序有问题rails_helper并且spec_helper 是分开的。

两个问题:

  1. 我怎样才能解决这个问题?
  2. 您可以推荐与最新 Rails 和 Rspec 一起使用的本地持续集成解决方案。

你只需要回答一个问题。

4

4 回答 4

5

以下修复对我有用:

#spec/spec_helper.rb
require 'rspec/core'
于 2015-06-01T12:36:06.013 回答
2

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

于 2014-12-17T05:39:15.193 回答
2

抛出一个可能是问题的快速答案。您的 spec_helper 文件应具有以下顺序:

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

在配置/环境需要之后需要 rspec/rails。

于 2014-09-20T00:01:46.377 回答
1

您应该在文件顶部添加以下要求spec_helper.rb

require 'rspec/rails'

参考这里:Zeus GitHub issue 308

于 2017-07-23T12:55:30.833 回答