Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby RSpec“;“没有要加载的此类文件”;错误_Ruby_Rspec_Rspec2 - Fatal编程技术网

Ruby RSpec“;“没有要加载的此类文件”;错误

Ruby RSpec“;“没有要加载的此类文件”;错误,ruby,rspec,rspec2,Ruby,Rspec,Rspec2,我在和RSpec纠缠不清,我就是不能让RSpec在我的Ruby项目中工作。甚至在RSpec官方主页的“立即开始”部分提供的简单示例中也没有: 因此,我从官方示例中获取代码,创建bowling.rb和bowling_spec.rb。当我尝试使用以下命令从控制台运行rspec时: rspec bowling_spec.rb --format nested 我得到这个输出: require': no such file to load -- bowling (LoadError) from C:/.

我在和RSpec纠缠不清,我就是不能让RSpec在我的Ruby项目中工作。甚至在RSpec官方主页的“立即开始”部分提供的简单示例中也没有:

因此,我从官方示例中获取代码,创建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'
require”:没有这样的文件要加载--bowling(LoadError)
来自C:/…/Ruby192/lib/ruby/site\u ruby/1.9.1/rubygems/custom\u require.rb:36:in'require'
来自C:/…/bowling_spec.rb:2:in`'
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in'load'
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:“加载规范文件中的块”
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in`map'
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:“加载规范文件”中
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_-line.rb:18:in“run”
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in'run\u in\u进程'
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in'run'
来自C:/…/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:在“自动运行中的块”中
我尝试在我自己的项目上使用Netbans 7.0.1和Aptanda Studio 3运行RSpec。我总是犯同样的错误。gem列表显示以下rspec gem:

  • rspec(2.6.0)
  • rspec核心(2.6.4)
  • rspec期望值(2.6.0)
  • rspec模拟(2.6.0)
  • rspec钢轨(2.6.1)
  • rspec轨道控制器(0.1.2)

有人能帮我解决这个问题吗?

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

gem install rspec -v 1.3.2

对于后代来说,我也有这个问题,问题是我在gem中的非规范类中意外地
require
'ed
spec\u helper.rb
。这很有趣。

在使用命令行时解决了这个问题。您必须将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。如果你这样做了,你应该知道你为什么这么做。