lib/coverage/kit.rb in coverage-kit-0.1.0 vs lib/coverage/kit.rb in coverage-kit-0.3.0

- old
+ new

@@ -1,32 +1,42 @@ require "coverage/kit/version" +require "simplecov" +require "simplecov-lcov" module Coverage module Kit - def self.setup(minimum_coverage: ) - return if ENV['COVERAGE'] == 'off' + def self.setup(minimum_coverage:) + return if ENV["COVERAGE"] == "off" @minimum_coverage = minimum_coverage @maximum_coverage = @minimum_coverage + 0.5 - require 'simplecov' - Coveralls.wear! if defined?(Coveralls) + SimpleCov.start do + if ENV["CI"] + SimpleCov::Formatter::LcovFormatter.config do |c| + c.report_with_single_file = true + c.single_report_path = "coverage/lcov.info" + end + formatter SimpleCov::Formatter::LcovFormatter + else + formatter SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::SimpleFormatter, + SimpleCov::Formatter::HTMLFormatter + ]) + end - formatters = [] - formatters << SimpleCov::Formatter::RcovFormatter if defined?(SimpleCov::Formatter::RcovFormatter) - formatters << Coveralls::SimpleCov::Formatter if defined?(Coveralls) - SimpleCov.formatters = formatters + enable_coverage :branch - SimpleCov.start do - add_filter '/vendor/' - add_filter '/config/' - add_filter '/spec/' - add_group 'lib', 'lib' + add_filter "/vendor/" + add_filter "/config/" + add_filter "/spec/" + add_group "lib", "lib" end + SimpleCov.at_exit do SimpleCov.result.format! percent = SimpleCov.result.covered_percent - puts "Coverage is #{'%.2f' % percent} (min: #{@minimum_coverage})" + puts "Coverage is #{"%.2f" % percent} (min: #{@minimum_coverage})" if percent < @minimum_coverage puts "Coverage must be above #{@minimum_coverage}" Kernel.exit(1) elsif percent > @maximum_coverage puts "Coverage must be below #{@maximum_coverage}. Time to bump coverage!"