diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2026-04-03 20:17:03 -0700 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2026-04-03 20:17:03 -0700 |
| commit | fda2bc4ee3045a17ca52ca6075cdd955a813fbc1 (patch) | |
| tree | a5eaf05b203579a2fe9eace0bd5b8df3362957ea | |
| parent | c38f8732c4ae6448cf05c795ddd5df4040ceeea8 (diff) | |
merge revision(s) 8ecf28f9384207590be73d5f2a95859cff9c526a: [Backport #21954]
[ruby/rubygems] Fix NoMethodError in Gem.try_activate when activation conflicts occur
| -rw-r--r-- | lib/rubygems.rb | 3 | ||||
| -rw-r--r-- | test/rubygems/test_gem.rb | 22 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index c0aacfc31b..a99aec3f97 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -192,8 +192,9 @@ module Gem 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 diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 74c8953904..4293bc5ba8 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1213,6 +1213,28 @@ class TestGem < Gem::TestCase 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" |
