Merge pull request #4188 from inspec/zenspider/fix_coverage

Fixed up interactions between minitest & simplecov.
This commit is contained in:
Ryan Davis 2019-06-06 11:32:55 -07:00 committed by GitHub
commit 651f0a83f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 11 deletions

View file

@ -5,7 +5,9 @@
# Do not add any other code to this code block. Simplecov and
# coveralls only until the next code block:
require 'simplecov'
if ENV['CI_ENABLE_COVERAGE']
require 'simplecov/no_defaults'
require "helpers/simplecov_minitest"
require 'coveralls'
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
@ -19,6 +21,7 @@ SimpleCov.start do
add_group 'Matchers', 'lib/matchers'
add_group 'Backends', 'lib/inspec/backend'
end
end
##
#

View file

@ -0,0 +1,60 @@
# frozen_string_literal: true
# Load default formatter gem
require "simplecov-html"
require "pathname"
require "simplecov/profiles/root_filter"
require "simplecov/profiles/test_frameworks"
require "simplecov/profiles/bundler_filter"
require "simplecov/profiles/rails"
# Default configuration
SimpleCov.configure do
formatter SimpleCov::Formatter::HTMLFormatter
load_profile "bundler_filter"
# Exclude files outside of SimpleCov.root
load_profile "root_filter"
end
# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
at_exit do
if defined? Minitest then
Minitest.after_run do
simplecov_at_exit
end
else
simplecov_at_exit
end
end
def simplecov_at_exit
# If we are in a different process than called start, don't interfere.
return if SimpleCov.pid != Process.pid
SimpleCov.set_exit_exception
SimpleCov.run_exit_tasks!
end
# Autoload config from ~/.simplecov if present
require "simplecov/load_global_config"
# Autoload config from .simplecov if present
# Recurse upwards until we find .simplecov or reach the root directory
config_path = Pathname.new(SimpleCov.root)
loop do
filename = config_path.join(".simplecov")
if filename.exist?
begin
load filename
rescue LoadError, StandardError
$stderr.puts "Warning: Error occurred while trying to load #{filename}. " \
"Error message: #{$!.message}"
end
break
end
config_path, = config_path.split
break if config_path.root?
end