diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index c9eeed2f8c76..262861a6f68a 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -803,7 +803,7 @@ def self.each_spec(dirs) # :nodoc: 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) @@ -834,9 +834,7 @@ def self.stubs_for(name) @@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 575bee4c14fc..0690572c730c 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1137,48 +1137,6 @@ def test_self_remove_spec_removed 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)