summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris HasiƄski <krzysztof.hasinski@gmail.com>2026-01-08 01:13:38 +0100
committerTakashi Kokubun <takashikkbn@gmail.com>2026-01-08 09:08:38 -0800
commit8d764da35768073c2e21ffeffa27ff2f3ab589b0 (patch)
treea77c70ca4feec20302ef69c6e15d031aef630f97
parentbe5d24eb0380360d0a1aeea99545d837ffe3eb24 (diff)
Fix incorrect bundled gems warning for hyphenated gem names
When requiring a file like "benchmark/ips", the warning system would incorrectly warn about the "benchmark" gem not being a default gem, even when the user has "benchmark-ips" (a separate third-party gem) in their Gemfile. The fix checks if a hyphenated version of the require path exists in the bundle specs before issuing a warning. For example, requiring "benchmark/ips" now checks for both "benchmark" and "benchmark-ips" in the Gemfile. [Bug #21828]
-rw-r--r--lib/bundled_gems.rb10
-rw-r--r--test/test_bundled_gems.rb13
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb
index 49fb90249d..3ac10aa256 100644
--- a/lib/bundled_gems.rb
+++ b/lib/bundled_gems.rb
@@ -124,6 +124,16 @@ module Gem::BUNDLED_GEMS # :nodoc:
return if specs.include?(name)
+ # Don't warn if a hyphenated gem provides this feature
+ # (e.g., benchmark-ips provides benchmark/ips, not the benchmark gem)
+ if subfeature
+ feature_parts = feature.split("/")
+ if feature_parts.size >= 2
+ hyphenated_gem = "#{feature_parts[0]}-#{feature_parts[1]}"
+ return if specs.include?(hyphenated_gem)
+ end
+ end
+
return if WARNED[name]
WARNED[name] = true
diff --git a/test/test_bundled_gems.rb b/test/test_bundled_gems.rb
index 19546dd296..6e25df9b01 100644
--- a/test/test_bundled_gems.rb
+++ b/test/test_bundled_gems.rb
@@ -32,4 +32,17 @@ class TestBundlerGem < Gem::TestCase
assert Gem::BUNDLED_GEMS.warning?(path, specs: {})
assert_nil Gem::BUNDLED_GEMS.warning?(path, specs: {})
end
+
+ def test_no_warning_for_hyphenated_gem
+ # When benchmark-ips gem is in specs, requiring "benchmark/ips" should not warn
+ # about the benchmark gem (Bug #21828)
+ assert_nil Gem::BUNDLED_GEMS.warning?("benchmark/ips", specs: {"benchmark-ips" => true})
+ end
+
+ def test_warning_without_hyphenated_gem
+ # When benchmark-ips is NOT in specs, requiring "benchmark/ips" should warn
+ warning = Gem::BUNDLED_GEMS.warning?("benchmark/ips", specs: {})
+ assert warning
+ assert_match(/benchmark/, warning)
+ end
end