0

我像这样运行 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 保存到环境变量或文件中。

4

2 回答 2

2

到目前为止,我想出了

SimpleCov.at_exit do
  IO.write('/tmp/result_tests_coverage', 'work-in-progress')
end
于 2017-11-03T02:16:14.667 回答
1

这有点乱七八糟,但这对我有用。(这是在 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
于 2020-02-23T23:20:06.967 回答