【问题标题】:Guard + Zeus + Rspec-Rails: undefined method 'configure' for Rspec:ModuleGuard + Zeus + Rspec-Rails:Rspec:Module 的未定义方法“配置”
【发布时间】:2014-09-19 18:06:18
【问题描述】:

我正在使用以下内容:

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 specrake 运行规范。

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

uninitialized constant ActiveSupport::Autoload (NameError)

我猜现在加载顺序有问题 rails_helperspec_helper 是分开的。

两个问题:

  1. 我该如何解决这个问题?
  2. 您是否可以推荐一种不同的本地持续集成解决方案,该解决方案适用于最新的 Rails 和 Rspec。

您只需回答一个问题。

【问题讨论】:

  • 您能否显示您的 spec_helper 文件以及您遇到该错误的哪一行?

标签: ruby-on-rails rspec guard zeus


【解决方案1】:

以下修复对我有用:

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

【讨论】:

  • 他不需要
  • 为我工作。你怎么知道你必须运行它?
【解决方案2】:

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

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

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

【讨论】:

  • 感谢您的信息,我有问题,我添加了您的解决方案
【解决方案3】:

以下内容:

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”表示差异(最好使用推荐的更改)。

【讨论】:

    【解决方案4】:

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

    require 'rspec/rails'
    

    参考这里:Zeus GitHub issue 308

    【讨论】:

      猜你喜欢
      • 2014-09-17
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      相关资源
      最近更新 更多