Skip to content

Commit 890c83e

Browse files
jeromedalbertmatzbot
authored andcommitted
[rubygems/rubygems] Fix bundle remove sometimes not removing gems
ruby/rubygems@e7f5f067e8
1 parent ac5661d commit 890c83e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/bundler/injector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def remove_gems_from_dependencies(builder, gems, gemfile_path)
184184
# @param [Array] gems Array of names of gems to be removed.
185185
# @param [Pathname] gemfile_path The Gemfile from which to remove dependencies.
186186
def remove_gems_from_gemfile(gems, gemfile_path)
187-
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/
187+
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2.*\)/
188188
new_gemfile = []
189189
multiline_removal = false
190190
File.readlines(gemfile_path).each do |line|

spec/bundler/commands/remove_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,4 +729,23 @@
729729
end
730730
end
731731
end
732+
733+
context "when gem definition has parentheses" do
734+
it "removes the gem" do
735+
gemfile <<-G
736+
source "https://gem.repo1"
737+
738+
gem("myrack")
739+
gem("myrack", ">= 0")
740+
gem("myrack", require: false)
741+
G
742+
743+
bundle "remove myrack"
744+
745+
expect(out).to include("myrack was removed.")
746+
expect(gemfile).to eq <<~G
747+
source "https://gem.repo1"
748+
G
749+
end
750+
end
732751
end

0 commit comments

Comments
 (0)