在需要加载rubygems(来自config / boot.rb文件)的操作(rspec相关)中,我收到以下错误消息:
~/config/boot.rb:1:in `require': no such file to load -- rubygems (LoadError)
~/config/boot.rb:1
from ~/config/application.rb:1:in `require'
from ~/config/application.rb:1
from ~/config/environment.rb:2:in `require'
from ~/config/environment.rb:2
from ~/spec/spec_helper.rb:3:in `require'
from ~/spec/spec_helper.rb:3
from ~/spec/models/user_spec.rb:1:in `require'
from ~/spec/models/user_spec.rb:1
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load'
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load_files'
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `each'
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/lib/ruby/1.8/spec/runner/options.rb:132:in `run_examples'
from /usr/lib/ruby/1.8/spec/runner/command_line.rb:9:in `run'
from /usr/bin/spec:3
我在SO上查找了这个错误并找到了以下主题: ruby gem not found although it is installed和 no such file to load -- rubygems (LoadError)
然而,他们都提到问题可能来自机器上存在多个版本的红宝石。实际情况就是这样,所以我决定使用RVM运行全新的ruby和rails安装。但我仍有同样的问题!
其他信息:
which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p136/bin/ruby
which rails
/usr/local/rvm/gems/ruby-1.9.2-p136/bin/rails
which gem
/usr/local/rvm/rubies/ruby-1.9.2-p136/bin/gem
gem --version
1.5.0
ls /usr/lib/ruby
1.8 1.9.1 gems
有什么想法吗?
答案 0 :(得分:1)
所以我显然使用命令rspec
而不是spec
解决了我的问题。如果有人能够解释幕后的实际情况,那就太棒了!
amokrane@san-francisco ~/Documents/prog/web/learning_rails/forecaster/spec $ spec models/user_spec.rb
/home/amokrane/Documents/prog/web/learning_rails/forecaster/config/boot.rb:1:in `require': no such file to load -- rubygems (LoadError)
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/config/boot.rb:1
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/config/application.rb:1:in `require'
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/config/application.rb:1
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/config/environment.rb:2:in `require'
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/config/environment.rb:2
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/spec/spec_helper.rb:3:in `require'
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/spec/spec_helper.rb:3
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/spec/models/user_spec.rb:1:in `require'
from /home/amokrane/Documents/prog/web/learning_rails/forecaster/spec/models/user_spec.rb:1
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load'
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:15:in `load_files'
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `each'
from /usr/lib/ruby/1.8/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/lib/ruby/1.8/spec/runner/options.rb:132:in `run_examples'
from /usr/lib/ruby/1.8/spec/runner/command_line.rb:9:in `run'
from /usr/bin/spec:3
amokrane@san-francisco ~/Documents/prog/web/learning_rails/forecaster/spec $ rspec models/weather_spec.rb
F
Failures:
1) Weather should be valid
Failure/Error: @weather = Weather.new
ActiveRecord::StatementInvalid:
Could not find table 'weathers'
# ./models/weather_spec.rb:6:in `new'
# ./models/weather_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.11124 seconds
1 example, 1 failure