使用jruby 1.6在Windows平台上使用rspec在rails上学习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'
找到教程中缺少的答案:
c:\ rails_projects \ sample_app> rails生成rspec:install
答案 0 :(得分:55)
运行后
rails generate rspec:install
将*_spec.rb
个文件放在(在您的示例中)c:\rails_projects\sample_app\spec\model
下。然后使用require_relative指定相对路径
require_relative '../spec_helper'
答案 1 :(得分:12)
运行以下命令
c:\rails_projects\sample_app>rails generate rspec:install
这会将spec_helper.rb
文件放在您的/spec
目录
答案 2 :(得分:4)
当您执行'rails generate rspec:install'
时,如果看到'Could not find generator rspec:install'
错误消息,请在项目'rspec-rails'
,:developnent
组中添加gem :test
Gemfile
如下所示。
group :development, :test do
gem 'rspec-rails'
end
在此之后,执行'bundle install'
并继续'rails generate rspec:install'
答案 3 :(得分:0)
这可能有用 - 如果rpsec
未在Win7环境中正确安装。
答案 4 :(得分:0)
我有同样的问题,但出于不同的原因:
在我spork.prefork
文件的spec_helper.rb
块中我有这行
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
但在上面需要的其中一个文件中spec/support/some_helper_file.rb
)是require 'spec_helper'
来电
删除这个不需要的需求解决了问题