Ruby-on-rails 在“要求”中:没有要加载的此类文件--spec_helper
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5150293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
in 'require': no such file to load -- spec_helper
提问by MBDJ
Came across this error when trying out the ruby on rails tutorial section with rspec on a windows platform using jruby 1.6:
在使用 jruby 1.6 的 Windows 平台上使用 rspec 尝试 ruby on rails 教程部分时遇到此错误:
c:\rails_projects\sample_app>bundle exec rspec spec/
org/jruby/RubyKernel.java:1038:in `require': no such file to load -- spec_helper
(LoadError)
from c:/rails_projects/sample_app/spec/controllers/pages_controller_spec .rb:1:in `(root)'
from org/jruby/RubyKernel.java:1063:in `load'
from c:/rails_projects/sample_app/spec/controllers/pages_controller_spec
.rb:386:in `load_spec_files'
from org/jruby/RubyArray.java:2458:in `collect'
from c:/jruby-1.6.0.RC2/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspe
c/core/configuration.rb:386:in `load_spec_files'
from c:/jruby-1.6.0.RC2/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspe
c/core/command_line.rb:18:in `run'
from c:/jruby-1.6.0.RC2/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspe
c/core/runner.rb:55:in `run_in_process'
from c:/jruby-1.6.0.RC2/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspe
c/core/runner.rb:46:in `run'
from c:/jruby-1.6.0.RC2/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspe
c/core/runner.rb:10:in `autorun'
from org/jruby/RubyProc.java:268:in `call'
from org/jruby/RubyProc.java:232:in `call'
Found the answer which appears missing from the tutorial:
找到了教程中缺少的答案:
c:\rails_projects\sample_app>rails generate rspec:install
c:\rails_projects\sample_app>rails 生成 rspec:install
回答by GregC
After running
运行后
rails generate rspec:install
Place your *_spec.rbfiles under (in your example) c:\rails_projects\sample_app\spec\model. Then specify relative path with require_relative
将您的*_spec.rb文件放在(在您的示例中)下c:\rails_projects\sample_app\spec\model。然后用 require_relative 指定相对路径
require_relative '../spec_helper'
回答by MBDJ
Run the following command
运行以下命令
c:\rails_projects\sample_app>rails generate rspec:install
This will put the spec_helper.rbfile in your /specdirectory
这会将spec_helper.rb文件放在您的/spec目录中
回答by intellectual_stretch
When you execute 'rails generate rspec:install', if you see 'Could not find generator rspec:install'error message, add gem 'rspec-rails'within :developnent, :testgroup in your project Gemfileas shown below.
执行时'rails generate rspec:install',如果看到'Could not find generator rspec:install'错误消息,请'rspec-rails'在:developnent, :testgroup 中添加 gem ,Gemfile如下所示。
group :development, :test do
gem 'rspec-rails'
end
After this, execute 'bundle install'and continue with 'rails generate rspec:install'
在此之后,执行'bundle install'并继续'rails generate rspec:install'
回答by DJSam
This might be of some use - in the event rpsecwasn't installed properly on a Win7 environment.
这可能会有用 - 如果rpsec没有在 Win7 环境中正确安装。
回答by ryan2johnson9
I had the same problem but for a different reason:
我遇到了同样的问题,但出于不同的原因:
in my spork.preforkblock within my spec_helper.rbfile I had this line
在我的文件中的spork.prefork块中,我spec_helper.rb有这一行
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
but within one of the files that was being required above (spec/support/some_helper_file.rb) was a require 'spec_helper'call
但是在上面需要的文件之一 ( spec/support/some_helper_file.rb) 中有一个require 'spec_helper'调用
removing this unneeded require solved the issue
删除这个不需要的要求解决了这个问题

