summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel E. Giddins <segiddins@segiddins.me>2015-02-26 16:13:06 -0800
committerSamuel E. Giddins <segiddins@segiddins.me>2015-02-26 16:13:06 -0800
commited8182e4d460e0e7e6206817404f40e63552c85d (patch)
tree0f1a508a6baf466ab0544f68adf4d0d8a651ea8d
parentc40d129e9da8072eaf087ffdb773a801c6c2218e (diff)
downloadbundler-ed8182e4d460e0e7e6206817404f40e63552c85d.tar.gz
[Source::Path] Properly prefer gemspecs that are closer to the path root
-rw-r--r--lib/bundler/source/path.rb3
-rw-r--r--spec/install/gemfile/path_spec.rb19
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index 1a32b132bd..2b53bc7831 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -130,7 +130,8 @@ module Bundler
index = Index.new
if File.directory?(expanded_path)
- Dir["#{expanded_path}/#{@glob}"].sort_by { |p| p.split(File::SEPARATOR).size }.each do |file|
+ # We sort depth-first since `<<` will override the earlier-found specs
+ Dir["#{expanded_path}/#{@glob}"].sort_by { |p| -p.split(File::SEPARATOR).size }.each do |file|
spec = Bundler.load_gemspec(file)
if spec
spec.loaded_from = file.to_s
diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb
index 07449201c2..6ba4096457 100644
--- a/spec/install/gemfile/path_spec.rb
+++ b/spec/install/gemfile/path_spec.rb
@@ -120,6 +120,25 @@ describe "bundle install with explicit source paths" do
should_be_installed "foo 1.0"
end
+ it "prefers gemspecs closer to the path root" do
+ build_lib "premailer", "1.0.0", :path => lib_path("premailer") do |s|
+ s.write "gemfiles/ruby187.gemspec", <<-G
+ Gem::Specification.new do |s|
+ s.name = 'premailer'
+ s.version = '1.0.0'
+ end
+ G
+ end
+
+ install_gemfile <<-G
+ gem "premailer", :path => "#{lib_path("premailer")}"
+ G
+
+ # Installation of the 'gemfiles' gemspec would fail since it will be unable
+ # to require 'premailer.rb'
+ should_be_installed "premailer 1.0.0"
+ end
+
it "supports gemspec syntax" do
build_lib "foo", "1.0", :path => lib_path("foo") do |s|
s.add_dependency "rack", "1.0"