RoR测试驱动开发 - `require':无法加载此类文件 - nokogiri(LoadError)

时间:2012-11-24 19:33:57

标签: ruby-on-rails tdd capybara ubuntu-12.04

我将在本教程中开发一些Ruby on Rails应用程序。 http://ruby.railstutorial.org/chapters/static-pages#sec-TDD

我创建了..._spec.rb文件。

但是当我运行命令 - bundle exec rspec spec/requests/static_pages_spec.rb

有错误 - require: cannot load such file -- nokogiri (LoadError).

任何人都可以帮助我吗?

完整的错误消息:

/home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/capybara-2.0.1/lib/capybara.rb:2:in `require': cannot load such file -- nokogiri (LoadError)
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/capybara-2.0.1/lib/capybara.rb:2:in `<top (required)>'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `require'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `each'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `block in require'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `each'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `require'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.2.1/lib/bundler.rb:128:in `require'
from /home/karlis/workspace/sample_app/config/application.rb:13:in `<top (required)>'
from /home/karlis/workspace/sample_app/config/environment.rb:2:in `require'
from /home/karlis/workspace/sample_app/config/environment.rb:2:in `<top (required)>'
from /home/karlis/workspace/sample_app/spec/spec_helper.rb:3:in `require'
from /home/karlis/workspace/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
from /home/karlis/workspace/sample_app/spec/requests/static_pages_spec.rb:1:in `require'
from /home/karlis/workspace/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/configuration.rb:784:in `load'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/configuration.rb:784:in `block in load_spec_files'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/configuration.rb:784:in `each'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/configuration.rb:784:in `load_spec_files'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/runner.rb:69:in `run'
from /home/karlis/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.0/lib/rspec/core/runner.rb:8:in `block in autorun'

2 个答案:

答案 0 :(得分:3)

解决此问题的最简单方法是手动更新水豚包,它解决了我的问题。 “捆绑更新capybara”

答案 1 :(得分:0)

在我的情况下,如果我没有Gemfile,宝石会自动定位,但是当我制作一个空的宝石时,我需要包含nokogiri和其他宝石。希望这会有所帮助。