diff options
author | The Bundler Bot <bot@bundler.io> | 2017-06-06 23:58:17 +0000 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-07-17 12:01:41 -0500 |
commit | fc943555bdbbd9926a01dbbc947522cb53cfdcfd (patch) | |
tree | 54131d9d1327a26e16a562e0f762407353a20858 | |
parent | 76f6459389b4eec6177ccd959fd7a3922d9ff034 (diff) | |
download | bundler-fc943555bdbbd9926a01dbbc947522cb53cfdcfd.tar.gz |
Auto merge of #5707 - bundler:seg-sort-by-name-spec-set, r=indirect
[SpecSet] Sort by name in #tsort
Closes #5696
This is required for backwards compatibility, see
issue #5696 for an example. The issue is that previous versions of bundler would have the load path in one (correct) order, and master has them in another (correct) order. So some projects depend on the load path ordering when multiple gems have the same requirable file.
- [x] Test case
(cherry picked from commit e32353b063292427beccdb48fd8d6d0c74555911)
# Conflicts:
# spec/runtime/setup_spec.rb
-rw-r--r-- | lib/bundler/spec_set.rb | 3 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 44 |
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 5fd6bd606f..9642633578 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -160,7 +160,8 @@ module Bundler end def tsort_each_node - @specs.each {|s| yield s } + # MUST sort by name for backwards compatibility + @specs.sort_by(&:name).each {|s| yield s } end def spec_for_dependency(dep, match_current_platform) diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 120aa03d7e..754ec94d17 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -109,6 +109,17 @@ RSpec.describe "Bundler.setup" do end context "load order" do + def clean_load_path(lp) + without_bundler_load_path = ruby!("puts $LOAD_PATH").split("\n") + lp = lp - [ + bundler_path.to_s, + bundler_path.join("gems/bundler-#{Bundler::VERSION}/lib").to_s, + tmp("rubygems/lib").to_s, + root.join("../lib").expand_path.to_s, + ] - without_bundler_load_path + lp.map! {|p| p.sub(/^#{system_gem_path}/, "") } + end + it "puts loaded gems after -I and RUBYLIB" do install_gemfile <<-G source "file://#{gem_repo1}" @@ -140,20 +151,14 @@ RSpec.describe "Bundler.setup" do gem "rails" G - ruby <<-RUBY + 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, - root.join("../lib").expand_path.to_s, - ] - load_path.map! {|lp| lp.sub(/^#{system_gem_path}/, "") } + load_path = clean_load_path(out.split("\n")) expect(load_path).to start_with( "/gems/rails-2.3.2/lib", @@ -165,6 +170,29 @@ RSpec.describe "Bundler.setup" do "/gems/rake-10.0.2/lib" ) end + + it "falls back to order the load path alphabetically for backwards compatibility" do + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "weakling" + gem "duradura" + gem "terranova" + G + + ruby! <<-RUBY + require 'rubygems' + require 'bundler/setup' + puts $LOAD_PATH + RUBY + + load_path = clean_load_path(out.split("\n")) + + expect(load_path).to start_with( + "/gems/weakling-0.0.3/lib", + "/gems/terranova-8/lib", + "/gems/duradura-7.0/lib" + ) + end end it "raises if the Gemfile was not yet installed" do |