Skip to content

Commit 53adeab

Browse files
committed
backport: added coverage_summary at the end of the default task; added possibility of creating a coverage report
1 parent 2759bb2 commit 53adeab

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

.simplecov

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
SimpleCov.start do
5-
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter if ENV['SILENT_SIMPLECOV']
5+
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter unless ENV['CI'] || ENV['COVERAGE_REPORT'] == 'true'
66
SimpleCov.command_name "Task##{$PROCESS_ID}"
77
SimpleCov.merge_timeout 20
88
add_group 'Core', %w[lib/pagy.rb lib/pagy/countless.rb lib/pagy/backend.rb lib/pagy/frontend.rb lib/pagy/exceptions.rb]

Rakefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'bundler/setup'
55
require 'bundler/gem_tasks'
66
require 'rake/testtask'
7+
require 'json'
78

89
if ENV['RUBOCOP'] || !ENV['CI']
910
require "rubocop/rake_task"
@@ -44,12 +45,20 @@ Rake::TestTask.new(:test_others) do |t|
4445
t.description = "Run tests in #{test_files.join(', ')}"
4546
end
4647

48+
desc 'Display SimpleCov coverage summary'
49+
task :coverage_summary do
50+
last_run = JSON.parse(File.read('coverage/.last_run.json'))
51+
result = last_run['result']['line']
52+
puts "\n>>> SimpleCov Coverage: #{result}% <<<"
53+
if result < 100.0
54+
Warning.warn "!!!!! Missing #{(100.0 - result).round(2)}% coverage !!!!!"
55+
puts "\n(run it again with COVERAGE_REPORT=true for a line-by-line HTML report @ coverage/index.html)" unless ENV['COVERAGE_REPORT']
56+
end
57+
end
58+
59+
# get the full list of of all the test tasks (and test files that each task run) with:
60+
# rake -D test_*
4761
desc "Run all the test tasks: #{test_tasks.keys.join(', ')}"
4862
task test: [*test_tasks.keys, :test_others]
4963

50-
task default: [:test, :rubocop]
51-
52-
53-
# get the full list of of all the test tasks
54-
# (and test files that each task run) with:
55-
# rake -D test_*
64+
task default: [:test, :rubocop, :coverage_summary]

pagy3-on-docker/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ services:
2727
environment:
2828
- ENABLE_OJ=${ENABLE_OJ:-true}
2929
- RUBOCOP=${RUBOCOP:-true}
30+
- COVERAGE_REPORT=${COVERAGE_REPORT:-false}
31+
ports:
32+
- "1234:1234" # RubyMine debugger
3033
stdin_open: true
3134
tty: true
3235

0 commit comments

Comments
 (0)