Search code examples
rubysimplecov

simplecov: extract coverage percentage


I run simplecov like this

# test/test_helper.rb
require 'simplecov'
SimpleCov.start do
  add_filter "/test/"
  coverage_dir "/tmp/coverage/"
end

Instead, or in addition to printing this

Coverage report generated for Unit Tests to /tmp/coverage. 30 / 31 LOC (96.77%) covered.

How can I tell ruby/simplecov to save the number 96.77 to an env variable or file.


Solution

  • So far I came up with

    SimpleCov.at_exit do
      IO.write('/tmp/result_tests_coverage', 'work-in-progress')
    end