使用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!
答案 0 :(得分:5)
您所描述的内容实质上是Zeus中的一个错误。 (它在提交中修复 - 请参阅下面的评论以获取链接)
你现在应该这样做是对的:
# Zeus does not preload RSpec
require 'rspec/core' unless defined? RSpec.configure
Q值。但是,这不会打破拆分轨道规格和仅使用spec_helper的PORO规格的整个目的吗?
一个。不是真的,因为这个分裂的目的是让RSpec在多个环境中使用;你的上下文是Rails,所以你需要rspec/rails
。
当您需要rspec/core
时,应该足以让Zeus进行启动(这应该需要rspec/rails
)。如果您发现Zeus仍无法正常工作,请执行建议的要求rspec/rails
,直到Zeus团队对其设置进行排序。
Q值。你问:或者这不重要,因为Zeus预先加载了Rails吗?
一个。正确,对你的情况无关紧要。问题实际上只是Zeus为一个全新项目生成的文件中的负载排序故障。
答案 1 :(得分:4)
最快且可能最小的修复方法是移动
require 'rpsec/rails'
以上
require 'spec_helper'
rails_helper.rb文件中的
所以它看起来如下:
require 'rpsec/rails'
require 'spec_helper'