[rubygems/rubygems] Fix bundle remove sometimes not removing gems

https://github.com/rubygems/rubygems/commit/e7f5f067e8
This commit is contained in:
Jerome Dalbert 2024-11-20 17:43:22 -08:00 committed by git
parent ac5661db7b
commit 890c83e607
2 changed files with 20 additions and 1 deletions

View File

@ -184,7 +184,7 @@ module Bundler
# @param [Array] gems Array of names of gems to be removed.
# @param [Pathname] gemfile_path The Gemfile from which to remove dependencies.
def remove_gems_from_gemfile(gems, gemfile_path)
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2.*\)/
new_gemfile = []
multiline_removal = false
File.readlines(gemfile_path).each do |line|

View File

@ -729,4 +729,23 @@ RSpec.describe "bundle remove" do
end
end
end
context "when gem definition has parentheses" do
it "removes the gem" do
gemfile <<-G
source "https://gem.repo1"
gem("myrack")
gem("myrack", ">= 0")
gem("myrack", require: false)
G
bundle "remove myrack"
expect(out).to include("myrack was removed.")
expect(gemfile).to eq <<~G
source "https://gem.repo1"
G
end
end
end