spec/danger_plugin_spec.rb in danger-rubocop-0.4.0 vs spec/danger_plugin_spec.rb in danger-rubocop-0.4.1

- old
+ new

@@ -49,20 +49,52 @@ allow(@rubocop).to receive(:`) .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb') .and_return(response_ruby_file) # Do it + @rubocop.lint(files: 'spec/fixtures/ruby*.rb') + + output = @rubocop.status_report[:markdowns].first.message + + # A title + expect(output).to include('Rubocop violations') + # A warning + expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!") + end + + it 'handles a rubocop report for specified files (legacy)' do + allow(@rubocop).to receive(:`) + .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb') + .and_return(response_ruby_file) + + # Do it @rubocop.lint('spec/fixtures/ruby*.rb') output = @rubocop.status_report[:markdowns].first.message # A title expect(output).to include('Rubocop violations') # A warning expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!") end + it 'appends --force-exclusion argument when force_exclusion is set' do + allow(@rubocop).to receive(:`) + .with('bundle exec rubocop -f json --force-exclusion spec/fixtures/ruby_file.rb') + .and_return(response_ruby_file) + + # Do it + @rubocop.lint(files: 'spec/fixtures/ruby*.rb', force_exclusion: true) + + output = @rubocop.status_report[:markdowns].first.message + + # A title + expect(output).to include('Rubocop violations') + # A warning + expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!") + end + it 'handles a rubocop report for files changed in the PR' do allow(@rubocop.git).to receive(:added_files).and_return([]) allow(@rubocop.git).to receive(:modified_files) .and_return(["spec/fixtures/another_ruby_file.rb"]) @@ -93,9 +125,24 @@ | File | Line | Reason | |----------------------------|------|----------------| | spec/fixtures/ruby_file.rb | 13 | Don't do that! | EOS expect(@rubocop.status_report[:markdowns].first.message).to eq(formatted_table.chomp) + end + + describe 'a filename with special characters' do + it 'is shell escaped' do + modified_files = [ + 'spec/fixtures/shellescape/ruby_file_with_parens_(abc).rb', + 'spec/fixtures/shellescape/ruby_file with spaces.rb', + 'spec/fixtures/shellescape/ruby_file\'with_quotes.rb' + ] + allow(@rubocop.git).to receive(:modified_files) + .and_return(modified_files) + allow(@rubocop.git).to receive(:added_files).and_return([]) + + expect { @rubocop.lint }.not_to raise_error + end end end end end end