-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7102e4
commit 37f41fc
Showing
9 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
lib/simplecov/exit_codes/minimum_coverage_by_group_check.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
module SimpleCov | ||
module ExitCodes | ||
class MinimumCoverageByGroupCheck | ||
def initialize(result, minimum_coverage_by_group) | ||
@result = result | ||
@minimum_coverage_by_group = minimum_coverage_by_group | ||
end | ||
|
||
def failing? | ||
minimum_violations.any? | ||
end | ||
|
||
def report | ||
minimum_violations.each do |violation| | ||
$stderr.printf( | ||
"%<criterion>s coverage by group %<group_name> (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%).\n", | ||
group_name: violation.fetch(:group_name), | ||
covered: SimpleCov.round_coverage(violation.fetch(:actual)), | ||
minimum_coverage: violation.fetch(:minimum_expected), | ||
criterion: violation.fetch(:criterion).capitalize | ||
) | ||
end | ||
end | ||
|
||
def exit_code | ||
SimpleCov::ExitCodes::MINIMUM_COVERAGE | ||
end | ||
|
||
private | ||
|
||
attr_reader :result, :minimum_coverage_by_group | ||
|
||
def minimum_violations | ||
@minimum_violations ||= | ||
compute_minimum_coverage_data.select do |achieved| | ||
achieved.fetch(:actual) < achieved.fetch(:minimum_expected) | ||
end | ||
end | ||
|
||
def compute_minimum_coverage_data | ||
minimum_coverage_data = [] | ||
|
||
minimum_coverage_by_group.each do |criterion, expected_percent| | ||
result.coverage_statistics_by_group.each do |group_name, group_statistics| | ||
group_statistics.fetch(criterion).each do |actual_coverage| | ||
minimum_coverage_data << { | ||
group_name: group_name, | ||
criterion: criterion, | ||
minimum_expected: expected_percent, | ||
actual: SimpleCov.round_coverage(actual_coverage.percent) | ||
} | ||
end | ||
end | ||
end | ||
|
||
minimum_coverage_data | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require "helper" | ||
|
||
RSpec.describe SimpleCov::ExitCodes::MinimumCoverageByGroupCheck do | ||
subject { described_class.new(result, minimum_coverage_by_group) } | ||
|
||
let(:result) { instance_double(SimpleCov::Result, coverage_statistics_by_file: stats) } | ||
let(:stats) { | ||
{ | ||
'Test Group 1' => { | ||
line: [SimpleCov::CoverageStatistics.new(covered: 8, missed: 2)], | ||
branch: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2) | ||
} | ||
} | ||
} | ||
|
||
context "everything exactly ok" do | ||
let(:minimum_coverage) { { 'Test Group 1' => {line: 80.0} } } | ||
|
||
it { is_expected.not_to be_failing } | ||
end | ||
|
||
context "coverage violated" do | ||
let(:minimum_coverage) { { 'Test Group 1' => {line: 90.0} } } | ||
|
||
it { is_expected.to be_failing } | ||
end | ||
|
||
context "coverage slightly violated" do | ||
let(:minimum_coverage) { { 'Test Group 1' => {line: 80.01} } } | ||
|
||
it { is_expected.to be_failing } | ||
end | ||
|
||
context "one criterion violated" do | ||
let(:minimum_coverage) { { 'Test Group 1' => {line: 80.0, branch: 90.0} } } | ||
|
||
it { is_expected.to be_failing } | ||
end | ||
end |