From ed8182e4d460e0e7e6206817404f40e63552c85d Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Thu, 26 Feb 2015 16:13:06 -0800 Subject: [Source::Path] Properly prefer gemspecs that are closer to the path root --- lib/bundler/source/path.rb | 3 ++- spec/install/gemfile/path_spec.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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" -- cgit v1.2.1