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

- old
+ new

@@ -11,49 +11,52 @@ @dangerfile = testing_dangerfile @rubocop = testing_dangerfile.rubocop end describe :lint_files do - before do - # Set up our stubbed JSON response - response = { + let(:response_ruby_file) do + { 'files' => [ { 'path' => 'spec/fixtures/ruby_file.rb', 'offenses' => [ { 'message' => "Don't do that!", 'location' => { 'line' => 13 } } ] - }, + } + ] + }.to_json + end + + let(:response_another_ruby_file) do + { + 'files' => [ { 'path' => 'spec/fixtures/another_ruby_file.rb', 'offenses' => [ { 'message' => "Don't do that!", 'location' => { 'line' => 23 } } ] } ] - } - @rubocop_response = response.to_json + }.to_json end it 'handles a rubocop report for specified files' do allow(@rubocop).to receive(:`) - .with('bundle exec rubocop -f json') - .and_return(@rubocop_response) + .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 + output = @rubocop.status_report[:markdowns].first.message - expect(output).to_not be_empty - # 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 @@ -62,38 +65,37 @@ allow(@rubocop.git).to receive(:added_files).and_return([]) allow(@rubocop.git).to receive(:modified_files) .and_return(["spec/fixtures/another_ruby_file.rb"]) allow(@rubocop).to receive(:`) - .with('bundle exec rubocop -f json') - .and_return(@rubocop_response) + .with('bundle exec rubocop -f json spec/fixtures/another_ruby_file.rb') + .and_return(response_another_ruby_file) @rubocop.lint - output = @rubocop.status_report[:markdowns].first + output = @rubocop.status_report[:markdowns].first.message - expect(output).to_not be_empty expect(output).to include('Rubocop violations') expect(output).to include("spec/fixtures/another_ruby_file.rb | 23 | Don't do that!") end it 'is formatted as a markdown table' do allow(@rubocop.git).to receive(:modified_files) .and_return(['spec/fixtures/ruby_file.rb']) allow(@rubocop.git).to receive(:added_files).and_return([]) allow(@rubocop).to receive(:`) - .with('bundle exec rubocop -f json') - .and_return(@rubocop_response) + .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb') + .and_return(response_ruby_file) @rubocop.lint formatted_table = <<-EOS ### Rubocop violations\n | File | Line | Reason | |----------------------------|------|----------------| | spec/fixtures/ruby_file.rb | 13 | Don't do that! | EOS - expect(@rubocop.status_report[:markdowns].first).to eq(formatted_table.chomp) + expect(@rubocop.status_report[:markdowns].first.message).to eq(formatted_table.chomp) end end end end end