Skip to content

Commit

Permalink
added coverage_summary at the end of the default task; added possibil…
Browse files Browse the repository at this point in the history
…ity of creating a coverage report
  • Loading branch information
ddnexus committed Apr 19, 2021
1 parent 0424b71 commit 3cc464b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .simplecov
@@ -1,7 +1,7 @@
# frozen_string_literal: true

SimpleCov.start do
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter if ENV['SILENT_SIMPLECOV'] == 'true'
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter unless ENV['CI'] || ENV['COVERAGE_REPORT'] == 'true'
SimpleCov.command_name "Task##{$PROCESS_ID}"
SimpleCov.merge_timeout 20
add_group 'Core', %w[lib/pagy.rb lib/pagy/countless.rb lib/pagy/backend.rb lib/pagy/frontend.rb lib/pagy/exceptions.rb]
Expand Down
15 changes: 13 additions & 2 deletions Rakefile
Expand Up @@ -4,13 +4,13 @@ require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'
require 'json'

RuboCop::RakeTask.new(:rubocop)

unless ENV['CI']
require 'rake/manifest'
Rake::Manifest::Task.new do |t|
t.patterns = %w[lib/**/* LICENSE.txt]
t.patterns = FileList.new.include('lib/**/*', 'LICENSE.txt').exclude('**/*.md')
t.manifest_file = 'pagy.manifest'
end
Expand Down Expand Up @@ -53,9 +53,20 @@ Rake::TestTask.new(:test_others) do |t|
t.description = "Run tests in #{test_files.join(', ')}"
end

desc 'Display SimpleCov coverage summary'
task :coverage_summary do
last_run = JSON.load_file('coverage/.last_run.json')
result = last_run['result']['line']
puts "\n>>> SimpleCov Coverage: #{result}% <<<"
if result < 100.0
Warning.warn "!!!!! Missing #{(100.0 - result).round(2)}% coverage !!!!!"
puts "\n(run it again with COVERAGE_REPORT=true for a line-by-line HTML report @ coverage/index.html)" unless ENV['COVERAGE_REPORT']
end
end

# get the full list of of all the test tasks (and test files that each task run) with:
# rake -D test_*
desc "Run all the test tasks: #{test_tasks.keys.join(', ')}"
task test: [*test_tasks.keys, :test_others]

task default: %i[test rubocop]
task default: %i[test rubocop coverage_summary]
2 changes: 1 addition & 1 deletion pagy-on-docker/docker-compose.yml
Expand Up @@ -26,7 +26,7 @@ services:
- user_home:/home/$USER
environment:
- ENABLE_OJ=${ENABLE_OJ:-true}
- RUN_RUBOCOP=${RUN_RUBOCOP:-true}
- COVERAGE_REPORT=${COVERAGE_REPORT:-false}
ports:
- "1234:1234" # RubyMine debugger
stdin_open: true
Expand Down

0 comments on commit 3cc464b

Please sign in to comment.