spec/jacoco_spec.rb in danger-jacoco-instacart-0.1.9 vs spec/jacoco_spec.rb in danger-jacoco-instacart-0.1.10
- old
+ new
@@ -19,11 +19,11 @@
before do
@dangerfile = testing_dangerfile
@my_plugin = @dangerfile.jacoco
modified_files = ['src/java/com/example/CachedRepository.java']
- added_files = ['src/java/Blah.java']
+ added_files = ['src/java/io/sample/UseCase.java']
allow(@dangerfile.git).to receive(:modified_files).and_return(modified_files)
allow(@dangerfile.git).to receive(:added_files).and_return(added_files)
end
@@ -36,11 +36,11 @@
@my_plugin.report path_a
expect(@dangerfile.status_report[:errors]).to eq(['Total coverage of 32.9%. Improve this to at least 50%',
'Class coverage is below minimum. Improve to at least 0%'])
expect(@dangerfile.status_report[:markdowns][0].message).to include('### JaCoCo Code Coverage 32.9% :warning:')
- expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Meta | Status |')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Required | Status |')
expect(@dangerfile.status_report[:markdowns][0].message).to include('|:---|:---:|:---:|:---:|')
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
end
it 'test regex class coverage' do
@@ -106,11 +106,11 @@
@my_plugin.report path_a
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
end
- it 'test with overlapped package coverage and lowwer class coverage' do
+ it 'test with overlapped package coverage and lower class coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_project_coverage_percentage = 50
@my_plugin.minimum_package_coverage_map = {
'com/example/' => 90,
@@ -121,10 +121,52 @@
@my_plugin.report path_a
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 80% | :warning: |')
end
+ it 'checks modified files when "only_check_new_files" attribute is false' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_c.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 50
+ @my_plugin.only_check_new_files = false
+
+ @my_plugin.report path_a
+
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('### JaCoCo Code Coverage 55.59% :white_check_mark:')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Required | Status |')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('|:---|:---:|:---:|:---:|')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 0% | :white_check_mark: |')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `io/sample/UseCase` | 66% | 0% | :white_check_mark: |')
+ end
+
+ it 'defaults "only_check_new_files" attribute to false' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_c.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 50
+
+ @my_plugin.report path_a
+
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 0% | :white_check_mark: |')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `io/sample/UseCase` | 66% | 0% | :white_check_mark: |')
+ end
+
+ it 'does _not_ check modified files when "only_check_new_files" attribute is true' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_c.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 50
+ @my_plugin.minimum_class_coverage_percentage = 70
+ @my_plugin.only_check_new_files = true
+
+ @my_plugin.report path_a
+
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('### JaCoCo Code Coverage 55.59% :white_check_mark:')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Required | Status |')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('|:---|:---:|:---:|:---:|')
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `io/sample/UseCase` | 66% | 70% | :warning: |')
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include('com/example/CachedRepository')
+ end
+
it 'adds a link to report' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_class_coverage_percentage = 80
@my_plugin.minimum_project_coverage_percentage = 50
@@ -166,9 +208,93 @@
@my_plugin.minimum_class_coverage_percentage = 80
@my_plugin.minimum_project_coverage_percentage = 50
expect { @my_plugin.report path_a, fail_no_coverage_data_found: false }.to_not raise_error(RuntimeError)
+ end
+
+ it 'prints default success subtitle' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 30
+ @my_plugin.minimum_class_coverage_percentage = 40
+
+ @my_plugin.report path_a
+
+ expected = "### JaCoCo Code Coverage 32.9% :white_check_mark:\n"
+ expected += "#### All classes meet coverage requirement. Well done! :white_check_mark:\n"
+ expected += "| Class | Covered | Required | Status |\n"
+ expected += "|:---|:---:|:---:|:---:|\n"
+ expected += "| `com/example/CachedRepository` | 50% | 40% | :white_check_mark: |\n"
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(expected)
+ end
+
+ it 'prints default failure subtitle' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 30
+ @my_plugin.minimum_class_coverage_percentage = 60
+
+ @my_plugin.report path_a
+
+ expected = "### JaCoCo Code Coverage 32.9% :white_check_mark:\n"
+ expected += "#### There are classes that do not meet coverage requirement :warning:\n"
+ expected += "| Class | Covered | Required | Status |\n"
+ expected += "|:---|:---:|:---:|:---:|\n"
+ expected += "| `com/example/CachedRepository` | 50% | 60% | :warning: |\n"
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(expected)
+ end
+
+ it 'prints custom success subtitle' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 30
+ @my_plugin.minimum_class_coverage_percentage = 40
+ @my_plugin.subtitle_success = 'You rock! 🔥'
+
+ @my_plugin.report path_a
+
+ expected = "### JaCoCo Code Coverage 32.9% :white_check_mark:\n"
+ expected += "#### You rock! 🔥\n"
+ expected += "| Class | Covered | Required | Status |\n"
+ expected += "|:---|:---:|:---:|:---:|\n"
+ expected += "| `com/example/CachedRepository` | 50% | 40% | :white_check_mark: |\n"
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(expected)
+ end
+
+ it 'prints custom failure subtitle' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 30
+ @my_plugin.minimum_class_coverage_percentage = 60
+ @my_plugin.subtitle_failure = 'Too bad :('
+
+ @my_plugin.report path_a
+
+ expected = "### JaCoCo Code Coverage 32.9% :white_check_mark:\n"
+ expected += "#### Too bad :(\n"
+ expected += "| Class | Covered | Required | Status |\n"
+ expected += "|:---|:---:|:---:|:---:|\n"
+ expected += "| `com/example/CachedRepository` | 50% | 60% | :warning: |\n"
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(expected)
+ end
+
+ it 'prints default class column title' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.report path_a
+
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Required | Status |')
+ end
+
+ it 'prints custom class column title' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.class_column_title = 'New files'
+
+ @my_plugin.report path_a
+
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| New files | Covered | Required | Status |')
end
end
end
end