Rails + RSpec - 不需要规范/支持文件;给出“未初始化的常量(NameError)”

时间:2014-08-29 15:17:04

标签: ruby-on-rails-4 rspec-rails

在我当前的项目中,我无法运行任何测试用例,因为我收到以下错误:

/home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Features (NameError)

完整追踪:

/home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::ZIP
/home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of ZIP was here
Coverage report generated for RSpec to /home/harsh/Documents/viburnix/cloud/viburnix/coverage. 11 / 56 LOC (19.64%) covered.
/home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Features (NameError)
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core.rb:112:in `configure'
    from /home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:1:in `<top (required)>'
    from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `block in <top (required)>'
    from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `each'
    from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `<top (required)>'
    from /home/harsh/Documents/viburnix/cloud/viburnix/spec/models/user_spec.rb:1:in `require'
    from /home/harsh/Documents/viburnix/cloud/viburnix/spec/models/user_spec.rb:1:in `<top (required)>'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `block in load_spec_files'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/bin/rspec:23:in `load'
    from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/bin/rspec:23:in `<main>'

spec/spec_helper.rbspec:install生成的标准文件,包括:

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

spec/support/helpers.rb中,我有:

RSpec.configure do |config|
  config.include Features::SessionHelpers, type: :feature
  config.include Mongoid::Matchers, type: :model
  config.include AuthenticationHelpers, type: :controller
end

它在第2行给出错误:Features::SessionHelpers

似乎它根本不需要代码或者没有按正确的顺序加载。

问题是,在7人团队中,我是唯一一个无法运行spec的人。任何帮助或方向都是非常需要的,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

很抱歉迟到的回复。该项目由另一个团队启动,是的,所有文件,模块和类都出现在正确的位置。问题是加载/要求(在spec_helper.rb)这些文件的顺序。虽然其他人在没有任何问题的情况下愉快地工作,但我不得不提前加载/需要一些必需的文件。

令我困惑的是2个问题:

  1. 我并不感到困惑,因为它对我不起作用。手动要求这些特定文件是有意义的,应该从一开始就是这样。我很困惑它是如何为其他人工作的?
  2. 我尝试制作一个与其他人完全相同的虚拟机。然而,我遇到了这个问题,揭穿了与OS或shell等有关的神话。
  3. 我已将这些行添加到spec_helper.rb,并在运行测试后但在投入作业之前对其进行评论。