>我像这样运行 simplecov
# test/test_helper.rb
require 'simplecov'
SimpleCov.start do
add_filter "/test/"
coverage_dir "/tmp/coverage/"
end
相反,或者除了打印这个
Coverage report generated for Unit Tests to /tmp/coverage. 30 / 31 LOC (96.77%) covered.
如何告诉 ruby/simplecov 将数字 96.77 保存到 env 变量或文件中。
到目前为止,
我想出了
SimpleCov.at_exit do
IO.write('/tmp/result_tests_coverage', 'work-in-progress')
end
这有点混乱,但它对我有用。(这是在 bash 中,调用生成覆盖率的命令,并在文件中具有 % 符号...
<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