2

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:

Community
  • 1
  • 1
Chris Hough
  • 3,389
  • 3
  • 41
  • 80

1 Answers1

7

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.

Ben Turner
  • 156
  • 1
  • 2