spec/danger_plugin_spec.rb in danger-rubocop-0.10.0 vs spec/danger_plugin_spec.rb in danger-rubocop-0.11.0
- old
+ new
@@ -147,10 +147,11 @@
'path' => 'spec/fixtures/ruby_file.rb',
'offenses' => [
{
'cop_name' => 'Syntax/WhetherYouShouldDoThat',
'message' => "Don't do that!",
+ 'severity' => 'warning',
'location' => { 'line' => 13 }
}
]
}
]
@@ -164,10 +165,11 @@
'path' => 'spec/fixtures/another_ruby_file.rb',
'offenses' => [
{
'cop_name' => 'Syntax/WhetherYouShouldDoThat',
'message' => "Don't do that!",
+ 'severity' => 'error',
'location' => { 'line' => 23 }
}
]
}
]
@@ -308,9 +310,47 @@
@rubocop.lint(fail_on_inline_comment: true, inline_comment: true)
expect(@rubocop.violation_report[:errors].first.to_s)
.to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: error }")
+ end
+ end
+
+ context 'with report_severity option' do
+ context 'file with error' do
+ it 'reports violations by rubocop severity' 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"])
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
+
+ allow(@rubocop).to receive(:`)
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/another_ruby_file.rb')
+ .and_return(response_another_ruby_file)
+
+ @rubocop.lint(report_severity: true, inline_comment: true)
+
+ expect(@rubocop.violation_report[:errors].first.to_s)
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/another_ruby_file.rb, line: 23, type: error }")
+ end
+ end
+
+ context 'file with warning' do
+ it 'reports violations by rubocop severity' do
+ allow(@rubocop.git).to receive(:added_files).and_return([])
+ allow(@rubocop.git).to receive(:modified_files)
+ .and_return(["spec/fixtures/ruby_file.rb"])
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
+
+ allow(@rubocop).to receive(:`)
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
+ .and_return(response_ruby_file)
+
+ @rubocop.lint(report_severity: true, inline_comment: true)
+
+ expect(@rubocop.violation_report[:warnings].first.to_s)
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: warning }")
+ end
end
end
context 'using standardrb cmd' do
it 'executes using the standardrb cmd' do