diff --git a/lib/covered/minitest.rb b/lib/covered/minitest.rb index d8e525a..1a56940 100644 --- a/lib/covered/minitest.rb +++ b/lib/covered/minitest.rb @@ -12,6 +12,9 @@ module Covered module Minitest + MINIMUM_COVERAGE = + Float(ENV.fetch('MINIMUM_COVERAGE', 100.0)) + def run(*) $covered.start @@ -26,5 +29,11 @@ def run(*) Minitest.after_run do $covered.finish $covered.call($stderr) + + stats = Covered::Statistics.new + + $covered.policy.each { stats << _1 } + + stats.validate! Covered::Minitest::MINIMUM_COVERAGE / 100.0 end end diff --git a/test/covered/minitest.rb b/test/covered/minitest.rb index 89ec7cd..a51acab 100644 --- a/test/covered/minitest.rb +++ b/test/covered/minitest.rb @@ -11,11 +11,20 @@ it "can run minitest test suite with coverage" do input, output = IO.pipe - - system({"COVERAGE" => "PartialSummary"}, test_path, out: output, err: output) + + env = { + "COVERAGE" => "PartialSummary", + "MINIMUM_COVERAGE" => "100.1" + } + + system(env, test_path, out: output, err: output) output.close + expect($?.exitstatus).not.to be(:zero?) + buffer = input.read + expect(buffer).to be =~ /(.*?) files checked; (.*?) lines executed; (.*?)% covered/ + expect(buffer).to be =~ /is less than required minimum of 100.1/ end end