diff options
author | Homu <homu@barosl.com> | 2016-02-11 10:22:12 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-02-11 10:22:12 +0900 |
commit | 1c2710639ccd8558c8467bb3cd2f95548306bc31 (patch) | |
tree | aff7df7055e89b03791d63ea24379adb7685d266 | |
parent | e220788471bd0f489e239aaf6e6ecdccf997cf53 (diff) | |
parent | 10ccab6a0dae411d722925fb9030475fd315db01 (diff) | |
download | bundler-1c2710639ccd8558c8467bb3cd2f95548306bc31.tar.gz |
Auto merge of #4268 - Elffers:hhh_fix_ruby-I, r=indirect
Place bundler loaded gems after -I and RUBYLIB
Previously, gems were being placed at the front of the LOAD_PATH. This
meant you couldn't override a gem by setting -I or RUBYLIB.
This patch places -I and RUBYLIB in front of loaded gems and matches the
behavior in RubyGems.
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 4 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 12 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 27 |
3 files changed, 42 insertions, 1 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index c8ebe2cb9a..0f567db12a 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -35,6 +35,10 @@ module Bundler Gem::Command.build_args = args end + def load_path_insert_index + Gem.load_path_insert_index + end + def loaded_specs(name) Gem.loaded_specs[name] end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index c2d5ad4b0a..e80a9eaeba 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -37,7 +37,17 @@ module Bundler Bundler.rubygems.mark_loaded(spec) load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path) } - $LOAD_PATH.unshift(*load_paths) + + # See Gem::Specification#add_self_to_load_path (since RubyGems 1.8) + insert_index = Bundler.rubygems.load_path_insert_index + + if insert_index + # Gem directories must come after -I and ENV['RUBYLIB'] + $LOAD_PATH.insert(insert_index, *load_paths) + else + # We are probably testing in core, -I and RUBYLIB don't apply + $LOAD_PATH.unshift(*load_paths) + end end setup_manpath diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index be3d1baf2b..d6c60dcf24 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -108,6 +108,33 @@ describe "Bundler.setup" do end end + context "load order" do + it "puts loaded gems after -I and RUBYLIB" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + ENV["RUBYOPT"] = "-Idash_i_dir" + ENV["RUBYLIB"] = "rubylib_dir" + + ruby <<-RUBY + require 'rubygems' + require 'bundler' + Bundler.setup + puts $LOAD_PATH + RUBY + + load_path = out.split("\n") + rack_load_order = load_path.index {|path| path.include?("rack") } + + expect(err).to eq("") + expect(load_path[1]).to include "dash_i_dir" + expect(load_path[2]).to include "rubylib_dir" + expect(rack_load_order).to be > 0 + end + end + it "raises if the Gemfile was not yet installed" do gemfile <<-G source "file://#{gem_repo1}" |