Rspec命令返回'`require':无法加载此类文件 - spec_helper'当rake spec没有

时间:2014-11-12 18:30:34

标签: ruby-on-rails ruby unit-testing rspec

我正在哼着我的单元测试。对于每个文件,我编写一个测试,然后在其上运行rspec以确保我正确地写了一些东西。我正在使用rvm,采购ruby v2.1.1。我成功运行了命令ruby -S spec/controllers/current_spec.rb 在某些时候,我为所有测试运行rake spec 在此之后,当我再次运行ruby -S spec/controllers/current_spec.rb时,我收到以下错误:

ruby -S spec/controllers/current_spec.rb 
   /home/eggmatters/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext
   /kernel_require.rb:55:in `require': cannot load such file -- spec_helper (LoadError)
from /home/eggmatters/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext
   /kernel_require.rb:55:in `require'
from spec/controllers/current_spec.rb:1:in `<main>'

我的规范的顶部包含:

require 'spec_helper'

哪个错误。 spec_helper应该是:spec/spec_helper.rb

此外,在运行rake规范时,它所做的只是为spec目录中的每个文件发出spec命令,例如:

$ rake spec:controllers
/home/eggmatters/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec 
  ./spec/controllers/some_controller_spec.rb 
  ./spec/controllers/another_controller_spec.rb 
  ./spec/controllers/this_controller_spec.rb 
  ./spec/controllers/current_controller_spec.rb 

我已经确认ruby -S确实指向/home/eggmatters/.rvm/rubies/ruby-2.1.1/bin/ruby -Swhich ruby)。

Gemfile看起来很好。运行bundle exec ruby -S ./spec/controllers/current_controller_spec.rb会引发相同的错误。

我已经开始运行rails generate spec:install,因为我开始发出命令就好了。成功运行之间没有对spec_helper进行任何更改。

捆绑安装不会改变任何内容。

发生了什么事?为什么rspec 突然没有找到spec_helper,当它需要它时?耙子对rspec做了什么突然打破呢?为什么rake规范工作而这个没有?

0 个答案:

没有答案