Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert adding loaded specs to Gem::Specification.stubs and Gem::Specification.stubs_for #3455

Merged
merged 1 commit into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/rubygems/specification.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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) }

Expand Down
42 changes: 0 additions & 42 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -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)
Expand Down