我像这样运行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变量或文件中。
答案 0 :(得分:1)
到目前为止,我想出了
SimpleCov.at_exit do
IO.write('/tmp/result_tests_coverage', 'work-in-progress')
end
答案 1 :(得分:1)
这有点杂乱无章,但这对我有用。 (这在bash中,调用生成coverage的命令,并在文件中带有%号...)
<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