summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-04-30 14:22:29 +0900
committerSamuel Giddins <segiddins@segiddins.me>2016-04-30 02:04:04 -0500
commit3538ef1428dac9d0d4b7112eaa02318f8c39fc5f (patch)
tree56bbb07a22a3e38a0186efb538ad28e5ea574a5c
parent0c8a516e61fb0ca6cec34e7b3663d95e29c8bb23 (diff)
downloadbundler-3538ef1428dac9d0d4b7112eaa02318f8c39fc5f.tar.gz
Auto merge of #4485 - bundler:seg-setup-loadpath-order, r=segiddins
[Runtime] Fix the ordering of the load path when there are dependencies It was previously getting reversed closes #4482
-rw-r--r--lib/bundler/runtime.rb22
-rw-r--r--spec/runtime/setup_spec.rb31
2 files changed, 41 insertions, 12 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 9d53e7528a..0b4dfeccb7 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -17,7 +17,7 @@ module Bundler
Bundler.rubygems.replace_entrypoints(specs)
# Activate the specs
- specs.each do |spec|
+ load_paths = specs.map do |spec|
unless spec.loaded_from
raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it."
end
@@ -36,18 +36,16 @@ module Bundler
end
Bundler.rubygems.mark_loaded(spec)
- load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path) }
-
- # See Gem::Specification#add_self_to_load_path (since RubyGems 1.8)
- insert_index = Bundler.rubygems.load_path_insert_index
+ spec.load_paths.reject {|path| $LOAD_PATH.include?(path) }
+ end.reverse.flatten
- 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
+ # See Gem::Specification#add_self_to_load_path (since RubyGems 1.8)
+ if insert_index = Bundler.rubygems.load_path_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
setup_manpath
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index 1b2b442fdd..f9528199cc 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -133,6 +133,37 @@ describe "Bundler.setup" do
expect(load_path[2]).to include "rubylib_dir"
expect(rack_load_order).to be > 0
end
+
+ it "orders the load path correctly when there are dependencies" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rails"
+ G
+
+ ruby <<-RUBY
+ require 'rubygems'
+ require 'bundler'
+ Bundler.setup
+ puts $LOAD_PATH
+ RUBY
+
+ load_path = out.split("\n") - [
+ bundler_path.to_s,
+ bundler_path.join("gems/bundler-#{Bundler::VERSION}/lib").to_s,
+ tmp("rubygems/lib").to_s,
+ ]
+ load_path.map! {|lp| lp.sub(/^#{system_gem_path}/, "") }
+
+ expect(load_path).to start_with(
+ "/gems/rails-2.3.2/lib",
+ "/gems/activeresource-2.3.2/lib",
+ "/gems/activerecord-2.3.2/lib",
+ "/gems/actionpack-2.3.2/lib",
+ "/gems/actionmailer-2.3.2/lib",
+ "/gems/activesupport-2.3.2/lib",
+ "/gems/rake-10.0.2/lib"
+ )
+ end
end
it "raises if the Gemfile was not yet installed" do