0

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.

american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80

2 Answers2

2

So far I came up with

SimpleCov.at_exit do
  IO.write('/tmp/result_tests_coverage', 'work-in-progress')
end
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80
1

This is kind of a hacky mess, but it's what works for me. (This is in bash, calls the command that generates the coverage, and has the % sign in the file...)

<command>  | tee -a log/coverage.log
coverage_string="$(grep "Coverage report generated" log/coverage.log)"
[[ "$coverage_string" =~ ([[:digit:]]+\.[[:digit:]]+\%) ]] && echo ${BASH_REMATCH[1]} > percent.txt
nroose
  • 1,689
  • 2
  • 21
  • 28