ruby – `require’:无法加载这样的文件 – spec_helper(LoadError)

前端之家收集整理的这篇文章主要介绍了ruby – `require’:无法加载这样的文件 – spec_helper(LoadError)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创造
bundler gem --test=rspec MyGem.

我正在获取存储库结构.

当我尝试运行rspec代码时,我收到以下错误

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

然后我尝试应用require relative但我仍然收到错误

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.
rspec spec/sheetal_spec.rb

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

假设您的代码位于lib文件夹中,则必须同时添加这两个代码.如果要在spec文件夹中运行测试,请将../lib添加到加载路径.

原文链接:https://www.f2er.com/ruby/269970.html

猜你在找的Ruby相关文章