2

I recently started working on a large Rails application. Simplecov says test coverage is above 90%. Very good.

However now and again I discover files that are not even loaded by the test suite. These files are actually used in production but for some reason nobody cared enough to even write the simplest test about them. As a result they are not counted in the coverage metrics.

It worries me since there is an unknown amount of code that is likely to break in prod without us noticing.

Am I the only one to have this problem? Is there a well-known solution? Can we have coverage metrics for files not loaded?

Samuel
  • 517
  • 3
  • 12
  • 2
    http://stackoverflow.com/q/22075516/438992? Haven't tried it. That and two other potential answers in http://stackoverflow.com/q/27184588/438992. – Dave Newton Jul 30 '15 at 14:17

2 Answers2

3

The contributors added new config optiontrack_files exactly for this purpose. For rails project the value could look like this

track_files '{app,lib}/**/*.rb'

More details here: https://github.com/colszowka/simplecov/pull/422

Milos Blasko
  • 614
  • 10
  • 25
1

I ended up adding this to my environments/test.rb:

config.eager_load = true
config.eager_load_paths += ["#{config.root}/lib"]

However adding lib/ can have downsides, such as loading generators and such. This post does a good job at explaining each approach pros and cons.

Samuel
  • 517
  • 3
  • 12