Skip to content

Instantly share code, notes, and snippets.

@fornellas
Created June 24, 2016 17:03
Show Gist options
  • Save fornellas/02192f5b55a063a794174753a93fdd24 to your computer and use it in GitHub Desktop.
Save fornellas/02192f5b55a063a794174753a93fdd24 to your computer and use it in GitHub Desktop.
simplecov with multiple Ruby executions
require 'securerandom'
require 'simplecov'
# Ensure a unique ID for each ruby process execution
SimpleCov.command_name("#{SecureRandom.uuid}_#{$0} #{ARGV}")
# Just save result, do not output anything here
SimpleCov.at_exit { SimpleCov.result }
# Ensure correct root always
SimpleCov.root File.dirname(__FILE__)
SimpleCov.start
# Ensure that all ruby process instances use Simplecov
task :simplecov_setup do
ENV['RUBYLIB'] = "#{Dir.pwd}:#{ENV['RUBYLIB']}"
ENV['RUBYOPT'] = '-r configure_simplecov'
sh 'rm -rf coverage/'
end
# Generate a final report, with all merged results
task :simplecov_report do
require 'simplecov'
SimpleCov.command_name('rake')
SimpleCov.minimum_coverage 97
SimpleCov.start
end
desc "Run all tests"
task test: [
:simplecov_setup,
:execute_tests,
:simplecov_report
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment