2014-09-27 52 views
4

With rspec-rails 3.0+测试设置分为spec_helperrails_helper,我注意到生成的spec_helper不是require 'rspec/rails'RSpec 3.1与Zeus,我应该在spec_helper中需要'rspec/rails'吗?

这使宙斯崩溃:

spec_helper.rb:5:in `<top (required)>': undefined method `configure' for RSpec:Module (NoMethodError) 

this issue最常见的回答是require 'rspec/rails'

但是,这不会击败拆分钢轨规格和PORO规格的全部目的,它只使用spec_helper?或者,这是不是重要的,因为宙斯预先装载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

相关但不是http://stackoverflow.com/questions/25939918/guard-zeus-rspec-rails-undefined-method-configure-for-rspecmodule – max 2014-09-27 10:55:37

+0

的副本另请参阅https:// github。com/burke/zeus/issues/474 – max 2014-11-07 18:39:42

+0

我有同样的问题。但是我没有在spec_helper.rb中添加任何东西来修复它,你有没有设置警戒? – 2014-11-10 13:34:58

回答

5

什么你所描述的主要是宙斯的错误。 (它是固定在提交 - 请参阅下面的评论链接)

你是正确的,你应该这样做,现在:

# Zeus does not preload RSpec 
require 'rspec/core' unless defined? RSpec.configure 

Q.但不会致使这次失败的全部目的拆分轨道规格和PORO规格,只是使用spec_helper? A.不是真的,因为分割的目的是/让RSpec在多个上下文中使用;你的上下文是Rails,所以你确实需要rspec/rails

当你需要rspec/core,这应该足以让宙斯做它的启动(这应该反过来需要rspec/rails)。如果你发现Zeus仍然不能工作,那么建议需要rspec/rails,直到Zeus团队对他们的设置进行整理。

问:你问:或者这不重要,因为宙斯预加载Rails呢?

A.正确,对您的情况无关紧要。这个问题实际上只是Zeus为一个全新项目生成的文件中的负载排序故障。

+0

现在问题现在由[this commit]修复(https://github.com/burke/zeus/commit/d126abfe42e05188e8ce85bbd87a4d7f02d1d9de)Zeus现在检查是否存在rails_helper并加载它。 – max 2014-11-11 15:13:39

2

最快可能侵入性最小的解决办法是在rails_helper.rb文件移动

require 'rpsec/rails' 

上述

require 'spec_helper' 

,使它看起来像下面这样:

require 'rpsec/rails' 
require 'spec_helper' 
相关问题