diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 4f2b64e652..ba90974657 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -801,7 +801,7 @@ class Gem::Specification < Gem::BasicSpecification def self.stubs @@stubs ||= begin pattern = "*.gemspec" - stubs = Gem.loaded_specs.values + installed_stubs(dirs, pattern) + default_stubs(pattern) + stubs = installed_stubs(dirs, pattern) + default_stubs(pattern) stubs = stubs.uniq { |stub| stub.full_name } _resort!(stubs) @@ -832,9 +832,7 @@ class Gem::Specification < Gem::BasicSpecification @@stubs_by_name[name] else pattern = "#{name}-*.gemspec" - stubs = Gem.loaded_specs.values + - installed_stubs(dirs, pattern).select { |s| Gem::Platform.match s.platform } + - default_stubs(pattern) + stubs = installed_stubs(dirs, pattern).select { |s| Gem::Platform.match s.platform } + default_stubs(pattern) stubs = stubs.uniq { |stub| stub.full_name }.group_by(&:name) stubs.each_value { |v| _resort!(v) } diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index afcdc0dab3..7b45f0a865 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1137,48 +1137,6 @@ dependencies: [] refute_includes Gem::Specification.stubs.map { |s| s.full_name }, 'a-1' end - def test_self_stubs - Gem.loaded_specs.clear - Gem::Specification.class_variable_set(:@@stubs, nil) - - dir_standard_specs = File.join Gem.dir, 'specifications' - dir_default_specs = Gem.default_specifications_dir - - # Create gemspecs in three locations used in stubs - loaded_spec = Gem::Specification.new 'a', '3' - Gem.loaded_specs['a'] = loaded_spec - save_gemspec 'a', '2', dir_default_specs - save_gemspec 'a', '1', dir_standard_specs - - full_names = ['a-3', 'a-2', 'a-1'] - assert_equal full_names, Gem::Specification.stubs.map { |s| s.full_name } - - Gem.loaded_specs.delete 'a' - Gem::Specification.class_variable_set(:@@stubs, nil) - end - - def test_self_stubs_for - Gem.loaded_specs.clear - Gem::Specification.class_variable_set(:@@stubs, nil) - - dir_standard_specs = File.join Gem.dir, 'specifications' - dir_default_specs = Gem.default_specifications_dir - - # Create gemspecs in three locations used in stubs - loaded_spec = Gem::Specification.new 'a', '3' - Gem.loaded_specs['a'] = loaded_spec - save_gemspec('a-2', '2', dir_default_specs) { |s| s.name = 'a' } - save_gemspec('a-1', '1', dir_standard_specs) { |s| s.name = 'a' } - - full_names = ['a-3', 'a-2', 'a-1'] - - assert_equal full_names, Gem::Specification.stubs_for('a').map { |s| s.full_name } - assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length - - Gem.loaded_specs.delete 'a' - Gem::Specification.class_variable_set(:@@stubs, nil) - end - def test_self_stubs_for_lazy_loading Gem.loaded_specs.clear Gem::Specification.class_variable_set(:@@stubs, nil)