Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
0.22.0 (2022-12-23)
0.22.1 (YYYY-MM-DD)
==========

## Enhancements
* `minimum_coverage_by_file` prints the name of the violating file. - (@philipritchey)[https://github.com/philipritchey]

0.22.0 (2022-12-23)
==========

## Enhancements
* On Ruby 3.2+, you can now use the new Coverage library feature for `eval` - See https://github.com/simplecov-ruby/simplecov/pull/1037. Thanks [@mame](https://github.com/mame)!

## Bugfixes
Expand Down
8 changes: 4 additions & 4 deletions features/minimum_coverage_by_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature:

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (75.01%)."
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (75.01%) in framework_specific.rb."
And the output should contain "SimpleCov failed with exit 2"

Scenario: Just passing it
Expand Down Expand Up @@ -48,8 +48,8 @@ Feature:

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage by file (80.00%) is below the expected minimum coverage (90.00%)."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%)."
And the output should contain "Line coverage by file (80.00%) is below the expected minimum coverage (90.00%) in some_class.rb."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%) in some_class.rb."
And the output should contain "SimpleCov failed with exit 2"

@branch_coverage
Expand All @@ -67,6 +67,6 @@ Feature:

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%)."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%) in some_class.rb."
And the output should not contain "Line coverage"
And the output should contain "SimpleCov failed with exit 2"
10 changes: 6 additions & 4 deletions lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def failing?
def report
minimum_violations.each do |violation|
$stderr.printf(
"%<criterion>s coverage by file (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%).\n",
"%<criterion>s coverage by file (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%) in %<filename>s.\n",
covered: SimpleCov.round_coverage(violation.fetch(:actual)),
minimum_coverage: violation.fetch(:minimum_expected),
criterion: violation.fetch(:criterion).capitalize
criterion: violation.fetch(:criterion).capitalize,
filename: File.basename(violation.fetch(:filename))
)
end
end
Expand All @@ -40,11 +41,12 @@ def minimum_violations

def compute_minimum_coverage_data
minimum_coverage_by_file.flat_map do |criterion, expected_percent|
result.coverage_statistics_by_file.fetch(criterion).map do |actual_coverage|
result.files.collect(&:filename).zip(result.coverage_statistics_by_file.fetch(criterion)).map do |filename, actual_coverage|
{
criterion: criterion,
minimum_expected: expected_percent,
actual: SimpleCov.round_coverage(actual_coverage.percent)
actual: SimpleCov.round_coverage(actual_coverage.percent),
filename: filename
}
end
end
Expand Down
14 changes: 13 additions & 1 deletion spec/exit_codes/minimum_coverage_by_file_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
subject { described_class.new(result, minimum_coverage_by_file) }

let(:result) do
instance_double(SimpleCov::Result, coverage_statistics_by_file: stats)
instance_double(SimpleCov::Result, coverage_statistics_by_file: stats, files: files)
end
let(:stats) do
{
line: [SimpleCov::CoverageStatistics.new(covered: 8, missed: 2)]
}
end
let(:files) do
SimpleCov::FileList.new(
[
SimpleCov::SourceFile.new(
"foo.rb",
{
"lines" => [nil, 8, 6, 7, 5, 3, 0, 9, 0, 3, 5, nil]
}
)
]
)
end

context "all files passing requirements" do
let(:minimum_coverage_by_file) { {line: 80} }
Expand Down