Simplecov: Model files missing from coverage report of rails engine

Created on 3 Dec 2015  路  11Comments  路  Source: simplecov-ruby/simplecov

Hello!

Thanks for this awesome project. I'm having a bit of trouble. Using the latest (0.11.1 as of this writing), I'm not getting coverage for some of my files. I know that the files are under test because I can force the specs to fail and, or remove them and see the test count go up or down. But for whatever reason, they are not included in the coverage HTML output.

From my spec_helper.rb:

# ...
require 'simplecov'

SimpleCov.start do
  add_group 'Controllers', 'app/controllers'
  add_group 'Models', 'app/models'
  add_group 'Serializers', 'app/serializers'
  add_group 'Engine::Concerns', 'lib/my_engine/concerns'
  add_group 'Engine::Policies', 'lib/my_engine/policies'
  add_group 'Engine::Errors', 'lib/my_engine/errors'
  add_group 'Engine::Stores', 'lib/my_engine/stores'
  add_filter 'db'
  add_filter 'spec'
end

# Eager load for code coverages purposes
Dir[Rails.root.parent.parent.join('app/controllers/**/*.rb')].each { |f| puts f; require f }
Dir[Rails.root.parent.parent.join('app/models/**/*.rb')].each { |f| puts f; require f }
Dir[Rails.root.parent.parent.join('app/serializers/**/*.rb')].each { |f| puts f; require f }
Dir[Rails.root.parent.parent.join('lib/**/*.rb')].each { |f| puts f; require f }
# ...

Am I missing something here? This has always worked for other projects, and it is definitely working for files in other directories (controllers, serializers). Not sure what could be happening...

Most helpful comment

I fixed this issue by setting this inside mylib/<engine_name>.rb file

if ENV['RAILS_ENV'] == 'test'
  require 'simplecov'
  SimpleCov.start 'rails'
  puts "required simplecov"
end

Also, you can put this in an initializer.

All 11 comments

Is this a problem that was also present for you on 0.10.0?

@xaviershay - Yes, in fact I was on 0.10.0 and upgraded to 0.11.1 before opening this issue just to make sure it wasn't the version.

I have exactly same problem

I have same problem, on 0.10 works fine. But in my case, the files are all in api/*

I'm also getting this issue. An arbitrary subset of models are appearing, but the majority are not.

Are you all aware of the default root_filter that will skip anything outside your SimpleCov.root? Please see the respective section in the readme: https://github.com/colszowka/simplecov#default-root-filter-and-coverage-for-things-outside-of-it

@colszowka - I did read that, but it didn't make a difference. I have a folder -- app. Inside are three directories -- controllers, models, and serializers. Coverage is written for controllers and serializers, but not for models. Following what you mention, I shouldn't see coverage for anything outside of SimpleCov.root. But, this is not the case. I can see some coverage.

Further, inside the lib folder, I can see coverage for many directories, but not all of them. This is what is confusing. Why do some subdirectories work in a given parent directory, but some don't? And why would changing SimpleCov.root suddenly allow the missing directories to show up when some of their siblings are already visible?

I ran into this problem as well and solved it by eager loading the app in test. It seems that otherwise coverage won't be recorded for files that aren't used by the tests. See http://stackoverflow.com/questions/22075516/simple-cov-gem-missing-untested-files

This is probably worth noting in the README, since the only mention of eager loading is currently within the section pertaining to Spring.

^^ I'm actually on v0.10, but it appears as though this issue was addressed in v.0.11 by https://github.com/colszowka/simplecov/pull/422

I'm closing this. I figured out what was happening - it was because I was loading the dummy rails app before Simplecov.start. I noticed after calling filters.clear that the models started showing up, but had zero coverage which wasn't accurate. After some investigating, I went to the readme again just to double check everything, and I found the mistake. Apologies for the run around!

I fixed this issue by setting this inside mylib/<engine_name>.rb file

if ENV['RAILS_ENV'] == 'test'
  require 'simplecov'
  SimpleCov.start 'rails'
  puts "required simplecov"
end

Also, you can put this in an initializer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DannyBen picture DannyBen  路  4Comments

andyhite picture andyhite  路  8Comments

fidothe picture fidothe  路  5Comments

juanbrein picture juanbrein  路  4Comments

cvandermeer picture cvandermeer  路  4Comments