Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ def self.try_activate(path)
begin
spec.activate
rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax
name = spec.name
spec = Gem::Specification.find_unloaded_by_path(path)
spec ||= Gem::Specification.find_by_name(spec.name)
spec ||= Gem::Specification.find_by_name(name)
if spec.nil?
raise e
else
Expand Down
22 changes: 22 additions & 0 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,28 @@ def test_try_activate_returns_true_for_activated_specs
assert Gem.try_activate("b"), "try_activate should still return true"
end

def test_try_activate_does_not_raise_no_method_error_on_activation_conflict
a1 = util_spec "a", "1.0" do |s|
s.files << "lib/a/old.rb"
end

a2 = util_spec "a", "2.0" do |s|
s.files << "lib/a/old.rb"
s.files << "lib/a/new_file.rb"
end

install_specs a1, a2

# Activate the older version
gem "a", "= 1.0"

# try_activate a file only in the newer version should not raise
# NoMethodError on nil (https://bugs.ruby-lang.org/issues/21954)
assert_nothing_raised do
Gem.try_activate("a/new_file")
end
end

def test_spec_order_is_consistent
b1 = util_spec "b", "1.0"
b2 = util_spec "b", "2.0"
Expand Down
Loading