[英]Guard + Zeus + Rspec-Rails: undefined method 'configure' for Rspec:Module
我正在使用以下內容:
Rails 4.1.1
guard-zeus 2.0.0
rspec-rails 3.0.1
開箱即用的默認rails g rspec:install
和guard init
當我運行guard
並保存規范文件時,出現錯誤:
undefined method `configure` for RSpec:Module (NoMethodError)
我可以使用rspec spec
和rake
運行規范。
在spec_helper
,如果我require 'rspec/rails
在 configure 塊之前使用require 'rspec/rails
,guard 工作正常,但是rspec spec
失敗並出現錯誤:
uninitialized constant ActiveSupport::Autoload (NameError)
我猜現在rails_helper
和spec_helper
是分開的,加載順序有問題。
兩個問題:
你只需要回答一個問題。
以下修復對我有用:
#spec/spec_helper.rb
require 'rspec/core'
拋出一個可能是問題的快速答案。 您的 spec_helper 文件應具有以下順序:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
在 config/environment require 之后需要需要 rspec/rails。
下列:
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' 表示差異(最好使用推薦的更改)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.