spec/jacoco_spec.rb in danger-jacoco-instacart-0.1.12.SNAPSHOT.1 vs spec/jacoco_spec.rb in danger-jacoco-instacart-0.1.12.SNAPSHOT.2
- old
+ new
@@ -23,45 +23,78 @@
modified_files = ['src/java/com/example/CachedRepository.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)
+ allow(File).to receive(:open).and_call_original
end
it :report do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_project_coverage_percentage = 50
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%. Class coverage is below minimum. Improve to at least 0%/)
+ @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 | 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 'creates supplied status file upon failure' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_project_coverage_percentage = 100
+ @my_plugin.minimum_class_coverage_percentage = 60
+ @my_plugin.file_to_create_on_failure = 'kmm.txt'
+
+ expect(File).to receive(:open).with('kmm.txt', 'w')
+ @my_plugin.report path_a
+ end
+
+ it 'creates default status file upon failure' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_class_coverage_percentage = 60
+
+ expect(File).to receive(:open).with('danger_jacoco_failure_status_file.txt', 'w')
+ @my_plugin.report path_a
+ end
+
+ it 'does _not_ create status file upon success' do
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
+
+ @my_plugin.minimum_class_coverage_percentage = 40
+ @my_plugin.file_to_create_on_failure = 'kmm.txt'
+
+ expect(File).to_not receive(:open).with('kmm.txt', 'w')
+ @my_plugin.report path_a
+ end
+
it 'test regex class coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_project_coverage_percentage = 50
@my_plugin.minimum_class_coverage_map = { '.*Repository' => 60 }
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%. Class coverage is below minimum. Improve to at least 0%/)
+ @my_plugin.report path_a
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 60% | :warning: |')
end
it 'test with package 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/' => 70 }
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
+ @my_plugin.report path_a
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
end
it 'test with bigger overlapped package coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@@ -70,11 +103,12 @@
@my_plugin.minimum_package_coverage_map = {
'com/example/' => 70,
'com/' => 90
}
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
+ @my_plugin.report path_a
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
end
it 'test with lower overlapped package coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@@ -83,11 +117,12 @@
@my_plugin.minimum_package_coverage_map = {
'com/example/' => 77,
'com/' => 30
}
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
+ @my_plugin.report path_a
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 77% | :warning: |')
end
it 'test with overlapped package coverage and bigger class coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@@ -97,11 +132,12 @@
'com/example/' => 77,
'com/' => 30
}
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
+ @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 lower class coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@@ -111,11 +147,12 @@
'com/example/' => 90,
'com/' => 85
}
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 80 }
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
+ @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"
@@ -148,11 +185,11 @@
@my_plugin.minimum_project_coverage_percentage = 50
@my_plugin.minimum_class_coverage_percentage = 70
@my_plugin.only_check_new_files = true
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 70%/)
+ @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: |')
@@ -163,11 +200,12 @@
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_class_coverage_percentage = 80
@my_plugin.minimum_project_coverage_percentage = 50
- expect { @my_plugin.report(path_a, 'http://test.com/') }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%. Class coverage is below minimum. Improve to at least 80%/)
+ @my_plugin.report(path_a, 'http://test.com/')
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| [`com/example/CachedRepository`](http://test.com/com.example/CachedRepository.html) | 50% | 80% | :warning: |')
end
it 'When option "fail_no_coverage_data_found" is set to optionally fail, it doesn\'t fail the execution' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@@ -225,11 +263,11 @@
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_project_coverage_percentage = 30
@my_plugin.minimum_class_coverage_percentage = 60
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 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"
@@ -259,11 +297,11 @@
@my_plugin.minimum_project_coverage_percentage = 30
@my_plugin.minimum_class_coverage_percentage = 60
@my_plugin.subtitle_failure = 'Too bad :('
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 60%/)
+ @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"
@@ -302,11 +340,11 @@
it 'branch coverage takes over line coverage for classes, when instruction coverage is not available' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_e.xml"
@my_plugin.minimum_class_coverage_percentage = 50
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 50%/)
+ @my_plugin.report path_a
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 42% | 50% | :warning: |')
end
it 'line coverage takes over for classes, when both instruction coverage and branch coverage are not available' do
@@ -347,10 +385,10 @@
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
@my_plugin.minimum_class_coverage_percentage = 55
@my_plugin.minimum_composable_class_coverage_percentage = 45
- expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 55%/)
+ @my_plugin.report path_a
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 55% | :warning: |')
end
end
end