diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 85790fc181..9440ab048a 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -1303,6 +1303,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def remove_unresolved_default_spec(spec) spec.files.each do |file| @path_to_default_spec_map.delete(file) + @path_to_default_spec_map.delete(file.sub(suffix_regexp, "")) end end diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index dc722f2e0f..b341249391 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -41,6 +41,10 @@ class TestGemRequire < Gem::TestCase assert require(path), "'#{path}' was already required" end + def refute_require(path) + refute require(path), "'#{path}' was not yet required" + 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" @@ -334,6 +338,22 @@ class TestGemRequire < Gem::TestCase assert_equal %w(default-2.0.0.0), loaded_spec_names end + def test_default_gem_require_activates_just_once + default_gem_spec = new_default_spec("default", "2.0.0.0", + nil, "default/gem.rb") + install_default_specs(default_gem_spec) + + assert_require "default/gem" + + times_called = 0 + + Kernel.stub(:gem, ->(name, requirement) { times_called += 1 }) do + refute_require "default/gem" + end + + assert_equal 0, times_called + end + def test_realworld_default_gem begin gem 'json'