`require': 无法加载此类文件 -- spec_helper (LoadError) [英] `require': cannot load such file -- spec_helper (LoadError)

查看:42
本文介绍了`require': 无法加载此类文件 -- spec_helper (LoadError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创作

bundler gem --test=rspec MyGem.

我在其中获取存储库结构.

in which I'm getting the repository structure.

当我尝试运行 rspec 代码时,出现以下错误:

When I try to run the rspec code I get the following error:

 `require': cannot load such file -- spec_helper (LoadError)

然后我尝试申请 require relative 但我仍然收到错误:

I then try to apply require relative but I still get an error:

sheetal@ubuntu:~/sheetal/spec$ rspec sheetal_spec.rb 
\/home/sheetal/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- spec_helper (LoadError)
    from /home/sheetal/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/sheetal/sheetal/spec/sheetal_spec.rb:1:in `<top (required)>'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/bin/rspec:23:in `load'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/bin/rspec:23:in `<main>'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
    from /home/sheetal/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'

推荐答案

您正在运行 spec 文件夹中的规范.这会弄乱加载路径.从项目的根目录运行规范:~/sheetal.

You're running the specs from the spec folder. This messes up the load path. Run specs from the root of your project: ~/sheetal.

rspec spec/sheetal_spec.rb

Rspec 自动将 speclib 文件夹添加到加载路径.如果您已经在 spec 文件夹中,rspec 会将 spec/spec 添加到加载路径中.

Rspec adds the spec and lib folders to the load path automatically. If you're already in the spec folder, rspec is going to add spec/spec to the load path instead.

假设您的代码在 lib 文件夹中,您必须将 .../lib 添加到加载中如果你想在 spec 文件夹中运行你的测试路径.

Assuming that you have your code in the lib folder, you would have to add both . and ../lib to the load path if you want to run your tests in the spec folder.

这篇关于`require': 无法加载此类文件 -- spec_helper (LoadError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆