From c47d453219bf6488446b05f9ba7386fc6e9c249f Mon Sep 17 00:00:00 2001 From: Hsing-Hui Hsu Date: Tue, 2 Feb 2016 20:54:01 -0800 Subject: 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. --- lib/bundler/runtime.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/bundler/runtime.rb') diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 6ef476b9..0b1e5f92 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 = Gem.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 -- cgit v1.2.3