【问题标题】:Ruby RSpec "no such file to load" ErrorRuby RSpec“没有要加载的文件”错误
【发布时间】:2013-04-10 22:32:36
【问题描述】:

我在 RSpec 中苦苦挣扎,我只是无法让 RSpec 在我的 Ruby 项目中工作。甚至在 RSpec 官方主页的“立即开始”部分提供的简单示例中也没有:http://rspec.info/

所以我从官方示例中获取代码并创建 Bowling.rb 和 Bowling_spec.rb。当我尝试从控制台运行 rspec 时:

rspec bowling_spec.rb --format nested

我得到这个输出:

require': no such file to load -- bowling (LoadError)
from C:/.../Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/.../bowling_spec.rb:2:in `<top (required)>'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `block in load_spec_files'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `map'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load_spec_files'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:18:in `run'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
from C:/.../Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun'

我尝试使用 Netbans 7.0.1 以及 Aptanda Studio 3 在我自己的项目上运行 RSpec。我总是遇到同样的错误。 gem 列表显示以下 rspec gem:

  • rspec (2.6.0)
  • rspec-core (2.6.4)
  • rspec-expectations (2.6.0)
  • rspec 模拟 (2.6.0)
  • rspec-rails (2.6.1)
  • rspec-rails-controller (0.1.2)

谁能帮我解决这个问题?

【问题讨论】:

  • 在使用命令行时解决了这个问题。您必须将 Bowling_spec.rb 放在 spec/bowling_spec.rb 中,并将 Bowling.rb 放在 lib/bowling.rb 中才能正常工作。不过,对于 Netbeans 和 Aptana,我仍然会遇到同样的错误。
  • 您是否使用require 'bowling'(或require 'bowling.rb')来加载文件?如果是这样,您可能想要使用require './path/to/bowling.rb' 或将您的lib 目录添加到您的加载路径。
  • 您应该很少需要直接要求 .rb。如果你这样做了,你可能应该知道你为什么这样做。

标签: ruby rspec rspec2


【解决方案1】:

让它在 Netbeans 中工作的解决方案也是手动安装 Rspec,因为 Netbeans 不支持 RSpec 版本 2:

gem install rspec -v 1.3.2

【讨论】:

    【解决方案2】:

    对于后代,我也遇到了这个问题,问题是我不小心在 gem 的非规范类中 require'ed spec_helper.rb那个很有趣。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      相关资源
      最近更新 更多