1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Remove multiline gem specifications correctly

https://github.com/rubygems/rubygems/commit/8dca0ad56e
This commit is contained in:
Carsten Wirth 2019-11-26 15:48:55 +01:00 committed by Hiroshi SHIBATA
parent c91915c183
commit 0ae5cd55e5
Notes: git 2020-06-05 07:33:51 +09:00
2 changed files with 37 additions and 2 deletions

View file

@ -180,8 +180,19 @@ module Bundler
def remove_gems_from_gemfile(gems, gemfile_path)
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/
# remove lines which match the regex
new_gemfile = IO.readlines(gemfile_path).reject {|line| line.match(patterns) }
new_gemfile = []
multiline_removal = false
IO.readlines(gemfile_path).each do |line|
if line.match(patterns)
multiline_removal = line.rstrip.end_with?(",")
# skip lines which match the regex
next
end
# skip followup lines until line does not end with ','
new_gemfile << line unless multiline_removal
multiline_removal = line.rstrip.end_with?(",") if multiline_removal
end
# remove line \n and append them with other strings
new_gemfile.each_with_index do |_line, index|

View file

@ -44,6 +44,30 @@ RSpec.describe "bundle remove" do
source "#{file_uri_for(gem_repo1)}"
G
end
context "when gem is specified in multiple lines" do
it "shows success for removed gem" do
gemfile <<-G
source '#{file_uri_for(gem_repo1)}'
gem 'git'
gem 'rack',
git: 'https://github.com/rack/rack',
branch: 'master'
gem 'nokogiri'
G
bundle! "remove rack"
expect(out).to include("rack was removed.")
gemfile_should_be <<-G
source '#{file_uri_for(gem_repo1)}'
gem 'git'
gem 'nokogiri'
G
end
end
end
context "when gem is not present in gemfile" do