我是测试的忠实粉丝,当我运行当前的覆盖率报告时,我注意到我的lib子文件夹与.rb文件没有被simplecov接收。
以下是我的spec_helper.rb文件中的设置:
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter
]
SimpleCov.minimum_coverage 90
SimpleCov.start do
coverage_dir 'tmp/coverage'
add_filter '/.bundle/'
add_filter '/spec/'
add_filter '/config/'
add_group 'Models', 'app/models'
add_group 'Controllers', 'app/controllers'
add_group 'Services', 'app/services'
add_group 'Helpers', 'app/helpers'
add_group 'Lib', 'lib'
add_group 'Mailers', 'app/mailers'
add_group "Long Files" do |src_file|
src_file.lines.count > 100
end
add_group 'Ignored Code' do |src_file|
open(src_file.filename).grep(/:nocov:/).any?
end
end
end
虽然我今天在该文件夹中没有太多内容,但我想弄清楚他们为什么不进来。目前,我原本希望在报告中看到我的lib/modules
文件夹b / c它有rake里面使用的helper_functions.rb文件。
=> the git issue #351
另外,我试过这些解决方案没有运气:
答案 0 :(得分:6)
我曾经遇到类似的问题,结果发现一些未报告的代码在SimpleCov启动之前被加载。例如,如果您通过rake
命令运行测试,如果您的Rakefile在调用spec_helper.rb脚本之前引入了一些库,那么这些库将无法报告。