diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index c7e93c9ee0..182b736c56 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -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| diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 7ac2ea9b26..84505169ca 100644 --- a/spec/bundler/commands/remove_spec.rb +++ b/spec/bundler/commands/remove_spec.rb @@ -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