diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-06-25 17:55:35 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-06-25 17:58:39 -0700 |
commit | fe29acb063aef06915f56cffe8764b131748db21 (patch) | |
tree | bdc7802a5fbd5c8d83e3b255003b554ea86e7550 | |
parent | a37d0a72997ccd79d23d4a98e98544a6203147b9 (diff) | |
download | bundler-fe29acb063aef06915f56cffe8764b131748db21.tar.gz |
Raise an activation error if a rubygem is already activated that conflicts with the Gemfile
-rw-r--r-- | lib/bundler/runtime.rb | 8 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 27 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 5471aae02b..f4a24b48d5 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -23,6 +23,14 @@ module Bundler raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it." end + if activated_spec = Gem.loaded_specs[spec.name] and activated_spec.version != spec.version + e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \ + "but your Gemfile requires #{spec.name} #{spec.version}. Consider using bundle exec." + e.name = spec.name + e.version_requirement = Gem::Requirement.new(spec.version.to_s) + raise e + end + Gem.loaded_specs[spec.name] = spec spec.load_paths.each do |path| $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path) diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index e3c133ff75..8623bc2e39 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -166,6 +166,33 @@ describe "Bundler.setup" do end end + describe "preactivated gems" do + it "raises an exception if a pre activated gem conflicts with the bundle" do + system_gems "thin-1.0", "rack-1.0.0" + build_gem "thin", "1.1", :to_system => true do |s| + s.add_dependency "rack" + end + + gemfile <<-G + gem "thin", "1.0" + G + + ruby <<-R + require 'rubygems' + gem "thin" + require 'bundler' + begin + Bundler.setup + puts "FAIL" + rescue Gem::LoadError => e + puts e.message + end + R + + out.should == "You have already activated thin 1.1, but your Gemfile requires thin 1.0. Consider using bundle exec." + end + end + # Rubygems returns loaded_from as a string it "has loaded_from as a string on all specs" do build_git "foo" |