I defined a simple rake task for running my ruby tests but have the problem that rake doesn’t load a gem with the version defined in Gemfile. It get a Gem::LoadError. Is there a way to tell rake which gem version to use?
Here are the gems installed on my system:
addressable (2.2.6, 2.2.4)
bundler (1.0.15)
libarchive (0.1.2)
nokogiri (1.5.0)
rake (0.9.2, 0.8.7)
rdf (0.3.3)
And this is my GemFile:
source :rubygems
gem 'nokogiri', '1.5.0'
gem 'rdf', '0.3.3'
gem 'addressable', '2.2.4'
gem 'libarchive', '0.1.2'
Here the rake task:
require 'rake/testtask'
task :default => [:test]
desc "Run basic tests"
Rake::TestTask.new do |test|
test.libs << "test"
test.test_files = Dir["test/test_*.rb"]
test.verbose = true
end
And this is the exception I get:
/Users/dummy/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1612:in `raise_if_conflicts': Unable to activate rdf-0.3.3, because addressable-2.2.6 conflicts with addressable (= 2.2.4) (Gem::LoadError)
I can solve the problem by uninstalling addressable 2.2.6 but I need the never version of that gem for another project.
Another solution could be to use rvm gemsets. But isn’t it simply possible to run rake with a given Gemfile specification?
Thanks
I think Brian’s suggestion should indeed to the trick:
Also, partitioning gemsets, using for instance rvm gemsets, would be another option… there shouldn’t be a need to uninstall any gem versions.
Another partitioning technique would be to install all gems inside the project directory (as opposed to installing them as system gems), using something akin to:
See http://gembundler.com/man/bundle-install.1.html for more info. Note that this latter solution would still require the
bundle execapproach to avoid the gem conflicts.Hope this helps,
Peter