diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2020-05-21 15:20:57 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-06-05 07:32:42 +0900 |
commit | f0f138aa5d5857fb435bfaef95201d530f6d35da (patch) | |
tree | e665dd7b562ad36a68a7d44a11dd640153586303 /test/rubygems/test_require.rb | |
parent | 07dca5c02c95322a39833705d3acd87b3adb00ac (diff) | |
download | ruby-f0f138aa5d5857fb435bfaef95201d530f6d35da.tar.gz |
[rubygems/rubygems] Fix `$LOADED_FEATURES` cache sometimes not respected
In the cases where the initial manually `-I` path resolution succeeded,
we were passing a full path to the original require effectively skipping
the `$LOADED_FEATURES` cache. With this change, we _only_ do the
resolution when a matching requirable path is found in a default gem. In
that case, we skip activation of the default gem if we detect that the
required file will be picked up for a `-I` path.
https://github.com/rubygems/rubygems/commit/22ad5717c3
Diffstat (limited to 'test/rubygems/test_require.rb')
-rw-r--r-- | test/rubygems/test_require.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index c6be26a658..af95320ce3 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -45,6 +45,35 @@ class TestGemRequire < Gem::TestCase refute require(path), "'#{path}' was not yet required" end + def test_respect_loaded_features_caching_like_standard_require + dir = Dir.mktmpdir("test_require", @tempdir) + + lp1 = File.join dir, 'foo1' + foo1 = File.join lp1, 'foo.rb' + + FileUtils.mkdir_p lp1 + File.open(foo1, 'w') { |f| f.write "class Object; HELLO = 'foo1' end" } + + lp = $LOAD_PATH.dup + + $LOAD_PATH.unshift lp1 + assert_require 'foo' + assert_equal "foo1", ::Object::HELLO + + lp2 = File.join dir, 'foo2' + foo2 = File.join lp2, 'foo.rb' + + FileUtils.mkdir_p lp2 + File.open(foo2, 'w') { |f| f.write "class Object; HELLO = 'foo2' end" } + + $LOAD_PATH.unshift lp2 + refute_require 'foo' + assert_equal "foo1", ::Object::HELLO + ensure + $LOAD_PATH.replace lp + Object.send :remove_const, :HELLO if Object.const_defined? :HELLO + end + # Providing -I on the commandline should always beat gems def test_dash_i_beats_gems a1 = util_spec "a", "1", {"b" => "= 1"}, "lib/test_gem_require_a.rb" |