From bc9e1cc3c48c3774a1c144d836fae602503b8c0e Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Wed, 27 Feb 2019 01:43:05 +0000 Subject: [PATCH] Ruby: Handle more gemspec sanitization --- .../dependabot/bundler/file_updater/gemspec_sanitizer.rb | 4 ++++ .../bundler/file_updater/gemspec_sanitizer_spec.rb | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bundler/lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb b/bundler/lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb index 5cf8bea5b0c..382bf4f37fa 100644 --- a/bundler/lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb +++ b/bundler/lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb @@ -51,6 +51,10 @@ def on_send(node) # that constant probably comes from a required file replace_version_assignments(node) + # Remove any uses of a VERSION constant (or similar), as + # that constant probably comes from a required file + replace_version_constant_references(node) + # Replace the `s.files= ...` assignment with a blank array, as # occassionally a File.open(..).readlines pattern is used replace_file_assignments(node) diff --git a/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb b/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb index 5048c03bd5b..630f62a14c3 100644 --- a/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb +++ b/bundler/spec/dependabot/bundler/file_updater/gemspec_sanitizer_spec.rb @@ -189,10 +189,13 @@ let(:content) { 'Spec.new { |s| s.version = "#{Example::Version}" }' } it { is_expected.to eq('Spec.new { |s| s.version = "#{"1.5.0"}" }') } end - # rubocop:enable Lint/InterpolationCheck - # rubocop:disable Lint/InterpolationCheck context "with a version constant used elsewhere in the file" do + let(:content) { 'Spec.new { |s| something == "v#{Example::Version}" }' } + it { is_expected.to eq('Spec.new { |s| something == "v#{"1.5.0"}" }') } + end + + context "with a version constant used in assignment in the file" do let(:content) { 'Spec.new { |s| something = "v#{Example::Version}" }' } it { is_expected.to eq('Spec.new { |s| something = "v#{"1.5.0"}" }') } end