【发布时间】:2014-11-22 07:28:08
【问题描述】:
使用rspec-rails 3.0+,测试设置分为spec_helper 和rails_helper,我注意到生成的spec_helper 没有require 'rspec/rails'。
这会导致宙斯崩溃:
spec_helper.rb:5:in `<top (required)>': undefined method `configure' for RSpec:Module (NoMethodError)
对this issue 的最常见回复是require 'rspec/rails'。
但这不会破坏拆分仅使用spec_helper 的导轨规格和 PORO 规格的全部目的吗?或者这无关紧要,因为 Zeus 无论如何都预加载了 Rails?
我应该在我的spec_helper 中做这样的事情吗?
# Zeus does not preload RSpec
require 'rspec/core' unless defined? RSpec.configure
注意在生成的rails_helper 中包含:
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
【问题讨论】:
-
我遇到了同样的问题。但是我没有在 spec_helper.rb 中添加任何东西就修复了它,你有保护设置吗?
-
是的,但我始终确保套件在没有 Guard 的情况下运行。
-
好的。找到它,
gem 'guard-rspec'将其添加到 gemfile,这可能有点奇怪,但我能够重现它,然后在添加后修复它。有某种依赖。它试图在加载之前访问 Rspec
标签: ruby-on-rails ruby rspec zeus