From 68b7578a9b9fc3d102765851a552846dfccf6db0 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 8 Oct 2021 16:44:11 +0200 Subject: [PATCH] Simplecov: Centralize filters setup --- .simplecov | 13 +++++++++++++ bin/msync | 30 +++++++----------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.simplecov b/.simplecov index 3654b3f9..febc6938 100644 --- a/.simplecov +++ b/.simplecov @@ -1,4 +1,17 @@ SimpleCov.start do + if ENV['SIMPLECOV_ROOT'] + SimpleCov.root(ENV['SIMPLECOV_ROOT']) + + filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults + + # Because simplecov filters everything outside of the SimpleCov.root + # This should be added, cf. + # https://github.com/colszowka/simplecov#default-root-filter-and-coverage-for-things-outside-of-it + add_filter do |src| + !(src.filename =~ /^#{SimpleCov.root}/) + end + end + add_group 'Source code', 'lib' add_group 'Unit tests', 'spec' diff --git a/bin/msync b/bin/msync index 650f1e2a..ae7d7124 100755 --- a/bin/msync +++ b/bin/msync @@ -2,34 +2,18 @@ if ENV['COVERAGE'] # This block allow us to grab code coverage when running this script. - # Note: This environment variable is set in Cucumber/Aruba configuration to collect reports' + # + # Note: This environment variable (ie. COVERAGE) is set in Cucumber/Aruba configuration to collect reports + simplecov_root = File.expand_path File.join(File.dirname(__FILE__), '..') + + # When running with aruba simplecov was using /tmp/aruba as the root folder. + # This is to force using the project folder + ENV['SIMPLECOV_ROOT'] = simplecov_root require 'simplecov' # https://github.com/simplecov-ruby/simplecov/issues/234 # As described in the issue, every process must have an unique name: SimpleCov.command_name "#{File.basename $PROGRAM_NAME} (pid: #{Process.pid})" - - # When running with aruba simplecov was using /tmp/aruba as the root folder. - # This is to force using the project folder - SimpleCov.root(File.join(File.expand_path(File.dirname(__FILE__)), '..')) - - SimpleCov.start do - filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults - - # Because simplecov filters everything outside of the SimpleCov.root - # This should be added, cf. - # https://github.com/colszowka/simplecov#default-root-filter-and-coverage-for-things-outside-of-it - add_filter do |src| - !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /project/ - end - - # Ignoring test folders and tmp for Aruba - add_filter '/spec/' - add_filter '/test/' - add_filter '/features/' - add_filter '/tmp/' - add_filter '/vendor/' - end end lib = File.expand_path('../../lib', __FILE__)