Autoloaded files arent tracked by simplecov
faraaz-deepsource opened this issue · 3 comments
When I autoload a file using Zeitwerk
it stops being tracked by simplecov. I created a repo with reproducible example this repo.
In the above repo, if you run the test with bundle exec rspec
at the end it outputs
Coverage report generated for RSpec to <some_path>/experminents/zeitest/coverage. 0 / 0 LOC (100.0%) covered.
even though it does run the test (fails when I change the test expectation or method's return string).
However, in spec_helper.rb
if I remove autoloading and manually require_relative
the file to test(lib/main.rb), the file starts getting tracked again, as i can see the output:
Coverage report generated for RSpec to /Users/faraaz/experminents/zeitest/coverage. 3 / 3 LOC (100.0%) covered.
Is this a bug? Am I setting up something(simplecov) wrongly?
In that repository things happen in this order:
- Loads
lib/autoloader.rb
, - which configures a loader,
- which is told to eager load,
- which eager loads
lib/main.rb
. SimpleCov.start
is called.
As you see, by the time simplecov
starts tracking, the file defining Main
was already loaded.
If you remove loader.eager_load
to lazy load Main
, you'll see it is reported.
Yes that fixed it thank you so much! Should I add this to README of zeitwerk or simplecov incase someone else faces a similar issue?
@faraaz-deepsource certainly not here.
I don't know in SimpleCov's. To me, this seems more like an overlook. But you can ask them if you wish anyway.