Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

[SpecSet] Sort by name in #tsort #5707

Merged
merged 2 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def lookup
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)
Expand Down
44 changes: 35 additions & 9 deletions spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@
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}"
Expand Down Expand Up @@ -139,22 +150,14 @@
gem "rails"
G

without_bundler_load_path = ruby!("puts $LOAD_PATH").split("\n")

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,
] - without_bundler_load_path
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",
Expand All @@ -166,6 +169,29 @@
"/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
Expand Down