Coverage report is different between load and require?

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):

Here’s the test for the above code:

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: aviator/aviator | Job 1 | lib/aviator/openstack/compute/v2/public/list_images.rb | Coveralls - Test Coverage History & Statistics. 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

Answering my own question. :slight_smile:

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.