rails 4 simpecov missing files

徘徊边缘 提交于 2019-12-10 10:51:28

问题


I am a huge fan of testing and when I run my current coverage reports I noticed that my lib sub folders with .rb files are not being picked up by simplecov.

Here is my setup in my spec_helper.rb file:

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

While I do not have much in that folder today, I am trying to figure out why they are not coming in. Currently, I would have expected to see my lib/modules folder in my reports b/c it has a helper_functions.rb file used by rake inside.

=> the git issue #351

Also, I have tried these solutions with no luck:

  • Simple cov gem missing untested files in Rails
  • simplecov not covering lib directory in Rails engine -- NOT a missing require
  • SimpleCov with multiple apps - or in short, how does Simplecov work?

回答1:


I once had a similar issue and it turned out that some of the unreported code was being loaded before SimpleCov was started. For example, if you are running your tests via a rake command, if your Rakefile pulls in some libraries before invoking the spec_helper.rb script, those libraries won't get reported.



来源:https://stackoverflow.com/questions/27184588/rails-4-simpecov-missing-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!