Skip to content

Commit

Permalink
Remove ruby method from the gemfile (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovro-bikic authored Oct 8, 2024
1 parent 114ad5f commit 9ad4ca5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/polariscope/scanner/codebase_health_score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def health_score
def gemfile_file
@gemfile_file ||= begin
file = Tempfile.new('Gemfile')
file.write(gemfile_content.gsub("gemspec\n", ''))
file.write(gemfile_content.gsub("gemspec\n", '').gsub(/^ruby.*$\R/, ''))
file.close
file
end
Expand Down
28 changes: 28 additions & 0 deletions spec/lib/polariscope/scanner/codebase_health_score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,33 @@
end
end
end

context 'when gemfile_content contains ruby method' do
let(:gemfile_content) { <<~GEMFILE }
ruby '2.5.5'
ruby('2.5.5')
ruby file: '.ruby-version'
gem :ruby
GEMFILE
let(:gemfile_lock_content) { 'gemfile lock content' }
let(:bundler_audit_config_content) { 'BundlerAuditIgnore' }
let(:gemfile_tempfile) { instance_double(Tempfile, write: :ok, close: :ok, unlink: :ok, path: 'Gemfile') }
let(:audit_tempfile) { instance_double(Tempfile, write: :ok, close: :ok, unlink: :ok, path: 'bundler-audit') }

before do
allow(Tempfile).to receive(:new).with('Gemfile').and_return(gemfile_tempfile)
allow(Tempfile).to receive(:new).with('.bundler-audit.yml').and_return(audit_tempfile)
end

it 'removes ruby method from the file' do
score

expect(Tempfile).to have_received(:new).with('Gemfile')
expect(gemfile_tempfile).to have_received(:write).with("\ngem :ruby\n")
expect(gemfile_tempfile).to have_received(:close)
expect(gemfile_tempfile).to have_received(:unlink)
end
end
end
end

0 comments on commit 9ad4ca5

Please sign in to comment.