simplecov-compare 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7ec00dedbd96313e447c4d4cd4b229cc6580a0b7594e695b37fa671a47c790b
4
- data.tar.gz: 75cf2e34a0ad0e6da31f7d0c2a476c17fe7e3a21c2cd45cf139e6c432f07481e
3
+ metadata.gz: 7ef291a274c59e3f99f89fe974daf3381494e612ebb413ffb22de5df14b5b281
4
+ data.tar.gz: a59c739a7ed6201beef06f28b21350a182055d6df21c23d1b2e02f2e321749b1
5
5
  SHA512:
6
- metadata.gz: 5a1bd555a0a92a6b2cc614b914a2c323ddc5aa012fee89c5796bed1dbd36f317dadb006d8f8b5f76adb4de0480a48e2bd6d014eaa040b023ec5d0bb62b509ee9
7
- data.tar.gz: 2176c41b305a0707e1e6043a5aa11416047344e19d9afa760a8c8699ffff02ae93633f43758f6ab24ca2b114ff6692bb19ce067006d167ef6e4fcecbba46ebe0
6
+ metadata.gz: 52f01295501e38c96606790de5bbc859c2f28e3e1f6ba81f7df61d455e60af2a28898c9c02fbe67cd0cb7ab09cfef1114384a24980a79a300ad5ff0e3a109063
7
+ data.tar.gz: c0fb9433dff8ac96c9862de9a6ef8636f63fc2f20dc2e1d092b229b8ed207126d338e46f631c3c66e5c9225e22cf293558acdd497e6cea01c140a543b6bcaa38
@@ -0,0 +1,25 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+
8
+ jobs:
9
+ tests:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby: [3.4, 4.0]
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Setup
23
+ run: ./bin/setup
24
+ - name: Run tests
25
+ run: bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,13 +1,35 @@
1
1
  ## Current release (in development)
2
2
 
3
+ ## 0.2.0 [2026-03-08]
4
+
5
+ * Markdown formatter shows the coverage before and after per file.
6
+
7
+ *Kevin Murphy*
8
+
9
+ * Expose the number of relevant and covered lines per file.
10
+
11
+ *Kevin Murphy*
12
+
13
+ * Add instructions about running on command line.
14
+
15
+ *Kevin Murphy*
16
+
17
+ * Test against Ruby 3.4 and 4.0.
18
+
19
+ *Kevin Murphy*
20
+
21
+ * Run tests in GitHub actions.
22
+
23
+ *Kevin Murphy*
24
+
3
25
  ## 0.1.1 [2026-03-08]
4
26
 
5
- * Add checks that file paths are provided
27
+ * Add checks that file paths are provided.
6
28
 
7
29
  *Kevin Murphy*
8
30
 
9
31
  ## 0.1.0 [2026-03-08]
10
32
 
11
- * Initial Release
33
+ * Initial Release.
12
34
 
13
35
  *Kevin Murphy*
data/README.md CHANGED
@@ -20,6 +20,18 @@ gem install simplecov-compare
20
20
 
21
21
  ## Usage
22
22
 
23
+ ### Command Line
24
+
25
+ Given an earlier coverage JSON output named `path/to/before.json` and a later
26
+ report named `path/to/after.json`, you can run:
27
+
28
+ ```sh
29
+ simplecov-compare path/to/before.json path/to/after.json
30
+ ```
31
+ ![result of simplecov-compare output in terminal](simplecov-compare-terminal.png?raw=true)
32
+
33
+ ### In Ruby
34
+
23
35
  Given an earlier coverage JSON output named `path/to/before.json` and a later
24
36
  report named `path/to/after.json`, you can run:
25
37
 
@@ -38,7 +38,43 @@ module Simplecov
38
38
  return @other.lines_covered_percent if @base.nil?
39
39
  return (-@base.lines_covered_percent) if @other.nil?
40
40
 
41
- @other.lines_covered_percent - @base.lines_covered_percent
41
+ (@other.lines_covered_percent - @base.lines_covered_percent).round(2)
42
+ end
43
+
44
+ def original_lines_covered_percent
45
+ return 0 if @base.nil?
46
+
47
+ @base.lines_covered_percent
48
+ end
49
+
50
+ def original_num_relevant_lines
51
+ return 0 if @base.nil?
52
+
53
+ @base.num_relevant_lines
54
+ end
55
+
56
+ def original_num_covered_lines
57
+ return 0 if @base.nil?
58
+
59
+ @base.num_covered_lines
60
+ end
61
+
62
+ def new_lines_covered_percent
63
+ return 0 if @other.nil?
64
+
65
+ @other.lines_covered_percent
66
+ end
67
+
68
+ def new_num_relevant_lines
69
+ return 0 if @other.nil?
70
+
71
+ @other.num_relevant_lines
72
+ end
73
+
74
+ def new_num_covered_lines
75
+ return 0 if @other.nil?
76
+
77
+ @other.num_covered_lines
42
78
  end
43
79
  end
44
80
  end
@@ -29,14 +29,22 @@ module Simplecov
29
29
  lines.select { _1.relevant? }
30
30
  end
31
31
 
32
+ def num_relevant_lines
33
+ relevant_lines.size
34
+ end
35
+
32
36
  def covered_lines
33
37
  lines.select { _1.covered? }
34
38
  end
35
39
 
40
+ def num_covered_lines
41
+ covered_lines.size
42
+ end
43
+
36
44
  def lines_covered_percent
37
- return 100 if relevant_lines.size.zero?
45
+ return 100 if num_relevant_lines.zero?
38
46
 
39
- ((covered_lines.size / relevant_lines.size.to_f) * 100).round(2)
47
+ ((num_covered_lines / num_relevant_lines.to_f) * 100).round(2)
40
48
  end
41
49
 
42
50
  def same_file?(other)
@@ -58,8 +58,8 @@ module Simplecov
58
58
  <<~FILE_DIFF
59
59
  ## File Differences
60
60
 
61
- | File Name | Coverage Change |
62
- | --------- | --------------- |
61
+ | File Name | Delta | From | To |
62
+ | --------- | ----- | ---- | -- |
63
63
  #{file_differences_table_contents(result_set_comparison)}
64
64
  FILE_DIFF
65
65
  else
@@ -76,7 +76,10 @@ module Simplecov
76
76
  .file_differences
77
77
  .sort_by { _1.lines_coverage_delta_points }
78
78
  .each_with_object(+"") do |file_difference, output|
79
- output << "| #{file_difference.filename} | #{file_difference.lines_coverage_delta_points} |\n"
79
+ output << "| #{file_difference.filename} "\
80
+ "| #{file_difference.lines_coverage_delta_points} "\
81
+ "| #{file_difference.original_lines_covered_percent}% (#{file_difference.original_num_covered_lines}/#{file_difference.original_num_relevant_lines}) "\
82
+ "| #{file_difference.new_lines_covered_percent}% (#{file_difference.new_num_covered_lines}/#{file_difference.new_num_relevant_lines}) |\n"
80
83
  end
81
84
  end
82
85
  end
@@ -20,11 +20,11 @@ module Simplecov
20
20
  end
21
21
 
22
22
  def num_relevant_lines
23
- files.sum { _1.relevant_lines.size }
23
+ files.sum { _1.num_relevant_lines }
24
24
  end
25
25
 
26
26
  def num_covered_lines
27
- files.sum { _1.covered_lines.size }
27
+ files.sum { _1.num_covered_lines }
28
28
  end
29
29
 
30
30
  def lines_covered_percent
@@ -28,7 +28,7 @@ module Simplecov
28
28
  return new_lines_covered_percent if @base.nil?
29
29
  return -original_lines_covered_percent if @other.nil?
30
30
 
31
- new_lines_covered_percent - original_lines_covered_percent
31
+ (new_lines_covered_percent - original_lines_covered_percent).round(2)
32
32
  end
33
33
 
34
34
  def file_differences
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Simplecov
4
4
  module Compare
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
Binary file
@@ -229,6 +229,108 @@ module Simplecov
229
229
  assert_equal(-50, comparison.lines_coverage_delta_points)
230
230
  end
231
231
  end
232
+
233
+ describe "#original_lines_covered_percent" do
234
+ it "is the lines coverage of the base file" do
235
+ base = Mocktail.of(FileResult)
236
+ stubs { base.lines_covered_percent }.with { 50 }
237
+
238
+ comparison = FileComparison.new(base, to: nil)
239
+
240
+ assert_equal 50, comparison.original_lines_covered_percent
241
+ end
242
+
243
+ it "is 0 with no base file" do
244
+ comparison = FileComparison.new(nil, to: nil)
245
+
246
+ assert_equal 0, comparison.original_lines_covered_percent
247
+ end
248
+ end
249
+
250
+ describe "#new_lines_covered_percent" do
251
+ it "is the lines coverage of the comparison file" do
252
+ other = Mocktail.of(FileResult)
253
+ stubs { other.lines_covered_percent }.with { 75 }
254
+
255
+ comparison = FileComparison.new(nil, to: other)
256
+
257
+ assert_equal 75, comparison.new_lines_covered_percent
258
+ end
259
+
260
+ it "is 0 with no comparison file" do
261
+ comparison = FileComparison.new(nil, to: nil)
262
+
263
+ assert_equal 0, comparison.new_lines_covered_percent
264
+ end
265
+ end
266
+
267
+ describe "#original_num_relevant_lines" do
268
+ it "is the number of relevant lines of the base file" do
269
+ base = Mocktail.of(FileResult)
270
+ stubs { base.num_relevant_lines }.with { 33 }
271
+
272
+ comparison = FileComparison.new(base, to: nil)
273
+
274
+ assert_equal 33, comparison.original_num_relevant_lines
275
+ end
276
+
277
+ it "is 0 with no base file" do
278
+ comparison = FileComparison.new(nil, to: nil)
279
+
280
+ assert_equal 0, comparison.original_num_relevant_lines
281
+ end
282
+ end
283
+
284
+ describe "#original_num_covered_lines" do
285
+ it "is the number of covered lines of the base file" do
286
+ base = Mocktail.of(FileResult)
287
+ stubs { base.num_covered_lines }.with { 17 }
288
+
289
+ comparison = FileComparison.new(base, to: nil)
290
+
291
+ assert_equal 17, comparison.original_num_covered_lines
292
+ end
293
+
294
+ it "is 0 with no base file" do
295
+ comparison = FileComparison.new(nil, to: nil)
296
+
297
+ assert_equal 0, comparison.original_num_covered_lines
298
+ end
299
+ end
300
+
301
+ describe "#new_num_relevant_lines" do
302
+ it "is the number of relevant lines of the comparison file" do
303
+ other = Mocktail.of(FileResult)
304
+ stubs { other.num_relevant_lines }.with { 42 }
305
+
306
+ comparison = FileComparison.new(nil, to: other)
307
+
308
+ assert_equal 42, comparison.new_num_relevant_lines
309
+ end
310
+
311
+ it "is 0 with no comparison file" do
312
+ comparison = FileComparison.new(nil, to: nil)
313
+
314
+ assert_equal 0, comparison.new_num_relevant_lines
315
+ end
316
+ end
317
+
318
+ describe "#new_num_covered_lines" do
319
+ it "is the number of covered lines of the comparison file" do
320
+ other = Mocktail.of(FileResult)
321
+ stubs { other.num_covered_lines }.with { 71 }
322
+
323
+ comparison = FileComparison.new(nil, to: other)
324
+
325
+ assert_equal 71, comparison.new_num_covered_lines
326
+ end
327
+
328
+ it "is 0 with no comparison file" do
329
+ comparison = FileComparison.new(nil, to: nil)
330
+
331
+ assert_equal 0, comparison.new_num_covered_lines
332
+ end
333
+ end
232
334
  end
233
335
  end
234
336
  end
@@ -38,6 +38,15 @@ module Simplecov
38
38
  end
39
39
  end
40
40
 
41
+ describe "#num_relevant_lines" do
42
+ it "provides the line count with relevant coverage information" do
43
+ coverage_data = { "lines" => [0, 1, nil, 47] }
44
+ file = FileResult.new(nil, coverage_data:)
45
+
46
+ assert_equal 3, file.num_relevant_lines
47
+ end
48
+ end
49
+
41
50
  describe "#covered_lines" do
42
51
  it "provides the lines that have been covered in the coverage report" do
43
52
  coverage_data = { "lines" => [0, 1, nil, 47] }
@@ -47,6 +56,15 @@ module Simplecov
47
56
  end
48
57
  end
49
58
 
59
+ describe "#num_covered_lines" do
60
+ it "provides the line count that have been covered in the coverage report" do
61
+ coverage_data = { "lines" => [0, 1, nil, 47] }
62
+ file = FileResult.new(nil, coverage_data:)
63
+
64
+ assert_equal 2, file.num_covered_lines
65
+ end
66
+ end
67
+
50
68
  describe "#lines_covered_percent" do
51
69
  it "is the percentage of relevant lines in the file that have been covered" do
52
70
  coverage_data = { "lines" => [0, 1, nil, 47] }
@@ -18,15 +18,42 @@ module Simplecov
18
18
  big_decrease = Mocktail.of(FileComparison)
19
19
  stubs { big_decrease.filename }.with { "big_decrease.rb" }
20
20
  stubs { big_decrease.lines_coverage_delta_points }.with { -20 }
21
+ stubs { big_decrease.original_lines_covered_percent }.with { 50 }
22
+ stubs { big_decrease.original_num_covered_lines }.with { 5 }
23
+ stubs { big_decrease.original_num_relevant_lines }.with { 10 }
24
+ stubs { big_decrease.new_lines_covered_percent }.with { 30 }
25
+ stubs { big_decrease.new_num_covered_lines }.with { 3 }
26
+ stubs { big_decrease.new_num_relevant_lines }.with { 10 }
27
+
21
28
  small_decrease = Mocktail.of(FileComparison)
22
29
  stubs { small_decrease.filename }.with { "small_decrease.rb" }
23
30
  stubs { small_decrease.lines_coverage_delta_points }.with { -3 }
31
+ stubs { small_decrease.original_lines_covered_percent }.with { 53 }
32
+ stubs { small_decrease.original_num_covered_lines }.with { 53 }
33
+ stubs { small_decrease.original_num_relevant_lines }.with { 100 }
34
+ stubs { small_decrease.new_lines_covered_percent }.with { 50 }
35
+ stubs { small_decrease.new_num_covered_lines }.with { 50 }
36
+ stubs { small_decrease.new_num_relevant_lines }.with { 100 }
37
+
24
38
  small_increase = Mocktail.of(FileComparison)
25
39
  stubs { small_increase.filename }.with { "small_increase.rb" }
26
40
  stubs { small_increase.lines_coverage_delta_points }.with { 7 }
41
+ stubs { small_increase.original_lines_covered_percent }.with { 0 }
42
+ stubs { small_increase.original_num_covered_lines }.with { 0 }
43
+ stubs { small_increase.original_num_relevant_lines }.with { 100 }
44
+ stubs { small_increase.new_lines_covered_percent }.with { 7 }
45
+ stubs { small_increase.new_num_covered_lines }.with { 7 }
46
+ stubs { small_increase.new_num_relevant_lines }.with { 100 }
47
+
27
48
  big_increase = Mocktail.of(FileComparison)
28
49
  stubs { big_increase.filename }.with { "big_increase.rb" }
29
50
  stubs { big_increase.lines_coverage_delta_points }.with { 25 }
51
+ stubs { big_increase.original_lines_covered_percent }.with { 25 }
52
+ stubs { big_increase.original_num_covered_lines }.with { 1 }
53
+ stubs { big_increase.original_num_relevant_lines }.with { 4 }
54
+ stubs { big_increase.new_lines_covered_percent }.with { 50 }
55
+ stubs { big_increase.new_num_covered_lines }.with { 2 }
56
+ stubs { big_increase.new_num_relevant_lines }.with { 4 }
30
57
 
31
58
  stubs { comparison.file_differences }.with { [big_increase, small_decrease, big_decrease, small_increase] }
32
59
 
@@ -39,12 +66,12 @@ module Simplecov
39
66
 
40
67
  ## File Differences
41
68
 
42
- | File Name | Coverage Change |
43
- | --------- | --------------- |
44
- | big_decrease.rb | -20 |
45
- | small_decrease.rb | -3 |
46
- | small_increase.rb | 7 |
47
- | big_increase.rb | 25 |
69
+ | File Name | Delta | From | To |
70
+ | --------- | ----- | ---- | -- |
71
+ | big_decrease.rb | -20 | 50% (5/10) | 30% (3/10) |
72
+ | small_decrease.rb | -3 | 53% (53/100) | 50% (50/100) |
73
+ | small_increase.rb | 7 | 0% (0/100) | 7% (7/100) |
74
+ | big_increase.rb | 25 | 25% (1/4) | 50% (2/4) |
48
75
 
49
76
 
50
77
  MARKDOWN
@@ -14,11 +14,11 @@ describe Simplecov::Compare do
14
14
 
15
15
  ## File Differences
16
16
 
17
- | File Name | Coverage Change |
18
- | --------- | --------------- |
19
- | /path/to/app/models/other_model.rb | 50.0 |
20
- | /path/to/app/models/model_name.rb | 81.82 |
21
- | /path/to/app/helpers/application_helper.rb | 100.0 |
17
+ | File Name | Delta | From | To |
18
+ | --------- | ----- | ---- | -- |
19
+ | /path/to/app/models/other_model.rb | 50.0 | 0% (0/0) | 50.0% (6/12) |
20
+ | /path/to/app/models/model_name.rb | 81.82 | 0% (0/0) | 81.82% (9/11) |
21
+ | /path/to/app/helpers/application_helper.rb | 100.0 | 0.0% (0/1) | 100.0% (1/1) |
22
22
 
23
23
 
24
24
  EXPECTED_OUTPUT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-compare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Murphy
@@ -31,6 +31,7 @@ executables:
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/test.yml"
34
35
  - CHANGELOG.md
35
36
  - CODE_OF_CONDUCT.md
36
37
  - LICENSE.txt
@@ -49,6 +50,7 @@ files:
49
50
  - lib/simplecov/compare/result_set_comparison.rb
50
51
  - lib/simplecov/compare/version.rb
51
52
  - sig/simplecov/compare.rbs
53
+ - simplecov-compare-terminal.png
52
54
  - test/fixtures/empty_resultset.json
53
55
  - test/fixtures/sample_resultset.json
54
56
  - test/simplecov/compare/file_comparison_test.rb