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.
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.
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