1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Respect files loaded from default gems before rubygems

f3da3c1190
This commit is contained in:
David Rodríguez 2020-03-25 15:55:16 +01:00 committed by Hiroshi SHIBATA
parent ff5ca548c3
commit f8f5e7fadf
Notes: git 2020-06-05 07:33:38 +09:00
3 changed files with 33 additions and 0 deletions

View file

@ -1226,6 +1226,8 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
next unless $~ next unless $~
end end
spec.activate if already_loaded?(file)
@path_to_default_spec_map[file] = spec @path_to_default_spec_map[file] = spec
@path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec @path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec
end end
@ -1291,6 +1293,18 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
attr_reader :pre_uninstall_hooks attr_reader :pre_uninstall_hooks
private
def already_loaded?(file)
default_gem_load_paths.find do |load_path_entry|
$LOADED_FEATURES.include?("#{load_path_entry}/#{file}")
end
end
def default_gem_load_paths
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1]
end
end end
## ##

View file

@ -803,6 +803,7 @@ class Gem::TestCase < Minitest::Test
lib_dir = File.join(@tempdir, "default_gems", "lib") lib_dir = File.join(@tempdir, "default_gems", "lib")
lib_dir.instance_variable_set(:@gem_prelude_index, lib_dir) lib_dir.instance_variable_set(:@gem_prelude_index, lib_dir)
Gem.instance_variable_set(:@default_gem_load_paths, [*Gem.instance_variable_get(:@default_gem_load_paths), lib_dir])
$LOAD_PATH.unshift(lib_dir) $LOAD_PATH.unshift(lib_dir)
files.each do |file| files.each do |file|
rb_path = File.join(lib_dir, file) rb_path = File.join(lib_dir, file)

View file

@ -300,6 +300,24 @@ class TestGemRequire < Gem::TestCase
$LOAD_PATH.replace lp if load_path_changed $LOAD_PATH.replace lp if load_path_changed
end end
def test_activate_via_require_respects_loaded_default_from_default_gems
a1 = new_default_spec "a", "1", nil, "a.rb"
# simulate requiring a default gem before rubygems is loaded
Kernel.send(:gem_original_require, "a")
# simulate registering default specs on loading rubygems
install_default_gems a1
a2 = util_spec "a", "2", nil, "lib/a.rb"
install_specs a2
refute_require 'a'
assert_equal %w[a-1], loaded_spec_names
end
def test_already_activated_direct_conflict def test_already_activated_direct_conflict
a1 = util_spec "a", "1", { "b" => "> 0" } a1 = util_spec "a", "1", { "b" => "> 0" }
b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb" b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"