summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-03-14 12:34:03 -0500
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-08-17 07:35:48 +0900
commit00cd5d74cecb6aa4a184e57e2b8246ef6e45d458 (patch)
tree2ff487a4b5e474ddd17bf2e083b4722d1a746b2b /lib
parentd4feeb19361a4d7addf4779fb6bdc8e8c072093b (diff)
[rubygems/rubygems] [Require] Ensure -I beats a default gem
https://github.com/rubygems/rubygems/commit/6fbda98eb3
Diffstat (limited to 'lib')
-rwxr-xr-xlib/rubygems/core_ext/kernel_require.rb20
-rw-r--r--lib/rubygems/test_case.rb1
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb
index 014090a..89e3e33 100755
--- a/lib/rubygems/core_ext/kernel_require.rb
+++ b/lib/rubygems/core_ext/kernel_require.rb
@@ -36,6 +36,26 @@ module Kernel
path = path.to_path if path.respond_to? :to_path
+ resolved_path = begin
+ rp = nil
+ $LOAD_PATH[0...Gem.load_path_insert_index].each do |lp|
+ Gem.suffixes.each do |s|
+ full_path = File.join(lp, "#{path}#{s}")
+ if File.file?(File.expand_path(full_path))
+ rp = full_path
+ break
+ end
+ end
+ break if rp
+ end
+ rp
+ end
+
+ if resolved_path
+ RUBYGEMS_ACTIVATION_MONITOR.exit
+ return gem_original_require(resolved_path)
+ end
+
if spec = Gem.find_unresolved_default_spec(path)
Gem.remove_unresolved_default_spec(spec)
begin
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index b6bb7ca..4b43df5 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -739,6 +739,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
spec.files = files
lib_dir = File.join(@tempdir, "default_gems", "lib")
+ lib_dir.instance_variable_set(:@gem_prelude_index, lib_dir)
$LOAD_PATH.unshift(lib_dir)
files.each do |file|
rb_path = File.join(lib_dir, file)