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
on 2013-08-31 21:47
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.