Skip to content

Commit 1a3e8b7

Browse files
committed
Fix Gemfile comma continuation check to ignore comments
1 parent 9a52331 commit 1a3e8b7

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

react_on_rails/lib/generators/react_on_rails/pro_generator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ def rewrite_react_on_rails_module_specifiers(content)
215215
end
216216

217217
def line_continues_with_comma?(line)
218-
line.rstrip.match?(/,\s*(?:#.*)?\z/)
218+
code_without_comment = line.sub(/\s*#.*\z/, "")
219+
code_without_comment.rstrip.end_with?(",")
219220
end
220221

221222
def print_success_message

react_on_rails/spec/react_on_rails/generators/pro_generator_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@
193193
expect(gemfile_content).not_to include("gem \"react_on_rails\" # pinned for compatibility")
194194
expect(generator).to have_received(:bundle_install_after_gem_swap)
195195
end
196+
197+
it "does not treat trailing comment commas as multiline continuation" do
198+
simulate_existing_file("Gemfile", <<~RUBY)
199+
source "https://rubygems.org"
200+
gem "react_on_rails" # keep this one,
201+
gem "rails"
202+
RUBY
203+
allow(generator).to receive(:bundle_install_after_gem_swap)
204+
205+
generator.send(:swap_base_gem_for_pro_in_gemfile)
206+
207+
gemfile_content = File.read(gemfile_path)
208+
expected_version = Gem::Version.new(ReactOnRails::VERSION).release.to_s
209+
expect(gemfile_content).to include("gem \"react_on_rails_pro\", \"~> #{expected_version}\"")
210+
expect(gemfile_content).to include("gem \"rails\"")
211+
expect(generator).to have_received(:bundle_install_after_gem_swap)
212+
end
196213
end
197214

198215
describe "#bundle_install_after_gem_swap" do

0 commit comments

Comments
 (0)