Ruby-on-rails 运行 Rspec 时出现“No such file to load”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/418792/
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
"No such file to load" error when running Rspec
提问by Ethan
Mac OS 10.4
rspec (1.1.11, 1.1.4, 1.1.3, 0.5.15)
rspec-rails (1.1.11)
rspec_generator (0.5.15)
rails 2.2.2
ruby 1.8.6 (2007-03-13 patchlevel 0) [universal-darwin8.0]
Created a new project...
创建了一个新项目...
$ rails myproject
Installed rspec into the project...
将 rspec 安装到项目中...
$ script/generate rspec
Generated a resource...
生成资源...
$ script/generate rspec_scaffold myresource name:string description:text
Tried to run specs...
试图运行规范...
$ rake spec
Got this error:
得到这个错误:
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- ./spec/models/../../vendor/generators/rspec/lib/rspec_on_rails (MissingSourceFile)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
from ./spec/models/../spec_helper.rb:3
from ./spec/models/entry_spec.rb:1:in `require'
from ./spec/models/entry_spec.rb:1
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- /Users/ethan/project/project/spec/../vendor/generators/rspec/lib/rspec_on_rails (MissingSourceFile)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
from /Users/ethan/project/project/spec/spec_helper.rb:3
from ./spec/controllers/entries_controller_spec.rb:1:in `require'
from ./spec/controllers/entries_controller_spec.rb:1
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
Indeed, there is no such file...
确实,没有这样的文件......
vendor/generators, ls:
供应商/生成器,ls:
rspec_controller rspec_model
采纳答案by Mihai A
It seems to work for me. I have installed rspec-rails, runned the rspec generator and when I give
它似乎对我有用。我已经安装了rspec-rails,运行了 rspec 生成器,当我给
$ script/generate
I get the list of generators:
我得到了生成器列表:
Installed Generators Rubygems: rspec, rspec_controller, rspec_model, rspec_scaffold Builtin: controller, integration_test, mailer, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
已安装的生成器 Rubygems:rspec、rspec_controller、rspec_model、rspec_scaffold 内置:控制器、integration_test、mailer、migration、model、observer、performance_test、plugin、resource、scaffold、session_migration
After generating the scaffold with rspec_scaffoldthe specs pass. Are the vendor/generators in your rails project ? I think you should delete them and use the generators from the gems instead.
使用rspec_scaffold生成脚手架后,规格通过。您的 rails 项目中是否有供应商/生成器?我认为您应该删除它们并改用 gem 中的生成器。
回答by bonyiii
For rails3
对于 rails3
To get the list
获取列表
$ rails generate
To generate spec_helper.rb
生成 spec_helper.rb
$ rails g rspec:install

