Simplecov: File in lib folder not tracked by simplecov

Created on 24 Jul 2015  路  5Comments  路  Source: simplecov-ruby/simplecov

rails 4.2.1
ruby 2.2.0p0

I have a file called harness.rb in the lib folder. It does not show up in my simplecov coverage report. I have other files in lib that are shown.

Most helpful comment

Actually Dir[Rails.root.join('lib/*.rb')].each {|file| load file } did not work for me.

I got:
spec/spec_helper.rb:9:in block in <top (required)>: uninitialized constant Rails (NameError)

But track_files '{app,lib}/**/*.rb' from this answer works just fine

All 5 comments

I have same problem regarding tracking app/controllers/concerns/*.rb files.

Please suggest solution.

Got the solution.

After SimpleCov.start "rails"

Load missing files like this (In this case I am loading lib/ files)

Dir[Rails.root.join('lib/*.rb')].each {|file| load file }

Please close this issue.

Cheers!

Yes, that worked. Thanks.

Actually Dir[Rails.root.join('lib/*.rb')].each {|file| load file } did not work for me.

I got:
spec/spec_helper.rb:9:in block in <top (required)>: uninitialized constant Rails (NameError)

But track_files '{app,lib}/**/*.rb' from this answer works just fine

I had to do Dir[Rails.root.join('lib/**/*.rb')].each { |file| load file } to get this to work for custom middleware. Doing load instead of require makes constants warn that they are already defined, but changing load to require doesn't track them. Is there a better way to do this?

For now I added stuff like FOO = 'bar' unless defined?(FOO) to stuff in lib to workaround this, but that doesn't seem ideal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PragTob picture PragTob  路  5Comments

jpatokal picture jpatokal  路  8Comments

cvandermeer picture cvandermeer  路  4Comments

vkodimut picture vkodimut  路  6Comments

DannyBen picture DannyBen  路  4Comments