summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-04-29 09:44:58 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-04-29 21:14:40 -0500
commitaeb55f18df64ef49ac6ae2fa69eecd893ca446a3 (patch)
tree71520a3c3dd2aacb6c24bffd96cfd48b4fc30391
parentebbdce0f9c38e7eacb00325d910a290628566fe7 (diff)
downloadbundler-aeb55f18df64ef49ac6ae2fa69eecd893ca446a3.tar.gz
[Runtime] Fix the ordering of the load path when there are dependencies
It was previously getting reversed
-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 c2f29a749f..5f36b25579 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.flatten.reverse
- 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..24d0b69ceb 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