зеркало из https://github.com/github/ruby.git
[rubygems/rubygems] Respect files loaded from default gems before rubygems
https://github.com/rubygems/rubygems/commit/f3da3c1190
This commit is contained in:
Родитель
ff5ca548c3
Коммит
f8f5e7fadf
|
@ -1226,6 +1226,8 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
|
|||
next unless $~
|
||||
end
|
||||
|
||||
spec.activate if already_loaded?(file)
|
||||
|
||||
@path_to_default_spec_map[file] = spec
|
||||
@path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec
|
||||
end
|
||||
|
@ -1291,6 +1293,18 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
|
|||
|
||||
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
|
||||
|
||||
##
|
||||
|
|
|
@ -803,6 +803,7 @@ class Gem::TestCase < Minitest::Test
|
|||
|
||||
lib_dir = File.join(@tempdir, "default_gems", "lib")
|
||||
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)
|
||||
files.each do |file|
|
||||
rb_path = File.join(lib_dir, file)
|
||||
|
|
|
@ -300,6 +300,24 @@ class TestGemRequire < Gem::TestCase
|
|||
$LOAD_PATH.replace lp if load_path_changed
|
||||
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
|
||||
a1 = util_spec "a", "1", { "b" => "> 0" }
|
||||
b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
|
||||
|
|
Загрузка…
Ссылка в новой задаче