rspec-rails 2.11.1 + rails 3.2.6

时间:2012-08-07 02:24:19

标签: ruby-on-rails ruby rspec bundler rspec-rails

我在我的应用程序中使用了rspec-rails 2.11.0,但是当我执行rspec spec /出现错误时。这是一堆错误:

/Users/diego/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:31:in `block in setup': You have already activated rspec-core 2.10.1, but your Gemfile requires rspec-core 2.11.1. Using bundle exec may solve this. (Gem::LoadError)
from /Users/diego/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:17:in `setup'
from /Users/diego/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler.rb:107:in `setup'
from /Users/diego/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/setup.rb:7:in `<top (required)>'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/diego/Development/Rails/carros/carros-web/config/boot.rb:6:in `<top (required)>'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/Development/Rails/carros/carros-web/config/application.rb:1:in `<top (required)>'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/Development/Rails/carros/carros-web/config/environment.rb:2:in `<top (required)>'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/Development/Rails/carros/carros-web/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/diego/Development/Rails/carros/carros-web/spec/models/admin_spec.rb:1:in `<top (required)>'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/diego/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'

有什么问题?这是我的宝石文件https://gist.github.com/3280825

2 个答案:

答案 0 :(得分:1)

正在发生的事情是您的rspec应用版本与全球环境版本不同。

当你执行rspec时,似乎正在使用来自global的那个。

使其工作的方法是使用bundle exec,如@prusswan所说,它将使用app env执行该命令(使用适当的gems版本等...)

此错误消息提及尝试bundle exec

答案 1 :(得分:0)

由于使用了bundler,虽然错误消息显示为“try”bundle exec,但如果您想确保只指定gem版本, 必须使用bundle exec运行它在Gemfile/Gemfile.lock中使用。另一种选择是使用binstubs,如here所述。