Forum: Ruby Coverage report is different between load and require?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
88112c5766888ac86c9b4336c9506fa2?d=identicon&s=25 Mark Maglana (mark_m46)
on 2013-08-31 21:47
I'm trying to understand why using load vs require results in different
coverage reports.

I'm writing a gem with dynamically loaded code that was previously not
detected by SimpleCov. I was able to partially fix this by rewriting the
code such that I can use Kernel::load instead of Object#instance_eval.
The remaining problem was that instance method definitions in my code
were reported by SimpleCov as not executed even though I clearly did.
For instance:

Here's a sample (Notice how #url and #headers are red):
https://coveralls.io/files/46749084

Here's the test for the above code:
https://github.com/relaxdiego/aviator/blob/develop...

Kernel.load(path, true) and Kernel.load(path, false) yielded the same
results. Then I realized that, with the recent changes I made, I can
also actually use require. When I did that, here are the updated
coverage report for that file: https://coveralls.io/files/46751330. So
the problem was solved as far as I was concerned.

My question is why the difference in the report when using load instead
of require?

P.S. Additional discussion on the original problem may be found in this
ticket: https://github.com/relaxdiego/aviator/issues/1
88112c5766888ac86c9b4336c9506fa2?d=identicon&s=25 Mark Maglana (mark_m46)
on 2013-09-01 00:11
Answering my own question. :-)

I loaded the files before checking if it was already loaded previously
(stupid mistake). Whereas require doesn't load the same file more than
once, load happily reloads code that was load earlier, the Coverage
module reports stats for that and since that newly reloaded code is not
executed, SimpleCov also reports that it didn't run.
This topic is locked and can not be replied to.