Skip to content

Commit 8d764da

Browse files
khasinskik0kubun
authored andcommitted
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]
1 parent be5d24e commit 8d764da

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

lib/bundled_gems.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ def self.warning?(name, specs: nil)
124124

125125
return if specs.include?(name)
126126

127+
# Don't warn if a hyphenated gem provides this feature
128+
# (e.g., benchmark-ips provides benchmark/ips, not the benchmark gem)
129+
if subfeature
130+
feature_parts = feature.split("/")
131+
if feature_parts.size >= 2
132+
hyphenated_gem = "#{feature_parts[0]}-#{feature_parts[1]}"
133+
return if specs.include?(hyphenated_gem)
134+
end
135+
end
136+
127137
return if WARNED[name]
128138
WARNED[name] = true
129139

test/test_bundled_gems.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ def test_warning_archdir
3232
assert Gem::BUNDLED_GEMS.warning?(path, specs: {})
3333
assert_nil Gem::BUNDLED_GEMS.warning?(path, specs: {})
3434
end
35+
36+
def test_no_warning_for_hyphenated_gem
37+
# When benchmark-ips gem is in specs, requiring "benchmark/ips" should not warn
38+
# about the benchmark gem (Bug #21828)
39+
assert_nil Gem::BUNDLED_GEMS.warning?("benchmark/ips", specs: {"benchmark-ips" => true})
40+
end
41+
42+
def test_warning_without_hyphenated_gem
43+
# When benchmark-ips is NOT in specs, requiring "benchmark/ips" should warn
44+
warning = Gem::BUNDLED_GEMS.warning?("benchmark/ips", specs: {})
45+
assert warning
46+
assert_match(/benchmark/, warning)
47+
end
3548
end

0 commit comments

Comments
 (0)