Skip to content

Commit 4797bf2

Browse files
Better partial summary if 100% test coverage.
1 parent 88a6fbd commit 4797bf2

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/covered/partial_summary.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ def print_coverage(terminal, coverage, before: 4, after: 4)
4141
def call(wrapper, output = $stdout, **options)
4242
terminal = self.terminal(output)
4343
complete_files = []
44+
partial_files_count = 0
4445

4546
statistics = self.each(wrapper) do |coverage|
47+
partial_files_count += 1
48+
4649
path = wrapper.relative_path(coverage.path)
4750
terminal.puts ""
4851
terminal.puts path, style: :path
@@ -66,8 +69,8 @@ def call(wrapper, output = $stdout, **options)
6669
terminal.puts
6770
statistics.print(output)
6871

69-
# Show information about files with 100% coverage
70-
if complete_files.any?
72+
# Only show information about files with 100% coverage if there were files with partial coverage shown above
73+
if complete_files.any? && partial_files_count > 0
7174
terminal.puts ""
7275
if complete_files.size == 1
7376
terminal.puts "1 file has 100% coverage and is not shown above:"

test/covered/partial_summary.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,41 @@
3333

3434
expect(io.string).to be(:include?, " :\n")
3535
end
36+
37+
it "shows 100% coverage files when there are partial files" do
38+
# Create a scenario with mixed coverage
39+
partial_file = __FILE__
40+
complete_file = File.join(__dir__, "../covered/summary.rb")
41+
42+
# Mark partial coverage for this file
43+
files.mark(partial_file, 1, 1)
44+
files.mark(partial_file, 2, 0) # uncovered line
45+
46+
# Mark complete coverage for summary.rb
47+
files.mark(complete_file, 1, 1)
48+
files.mark(complete_file, 2, 1)
49+
50+
summary.call(files, io)
51+
52+
# Should show the message about 100% coverage files
53+
expect(io.string).to be(:include?, "100% coverage and is not shown above:")
54+
expect(io.string).to be(:include?, "summary.rb")
55+
end
56+
57+
it "does not show 100% coverage files when all files are 100%" do
58+
# Create a scenario where all files have 100% coverage
59+
file1 = __FILE__
60+
file2 = File.join(__dir__, "../covered/summary.rb")
61+
62+
# Mark complete coverage for both files
63+
files.mark(file1, 1, 1)
64+
files.mark(file1, 2, 1)
65+
files.mark(file2, 1, 1)
66+
files.mark(file2, 2, 1)
67+
68+
summary.call(files, io)
69+
70+
# Should NOT show the message about 100% coverage files (would be redundant)
71+
expect(io.string).not.to be(:include?, "100% coverage and is not shown above:")
72+
end
3673
end

0 commit comments

Comments
 (0)