Result empty when fetched before SimpleCov naturally ends.

33 views
Skip to first unread message

jonas.schube...@gmail.com

unread,
Aug 24, 2015, 1:31:01 PM8/24/15
to SimpleCov
Hi there.

I'm building a gem to get my RSpec suite to fail if the coverage is under the limit set with SimpleCov. The current version can be seen at: https://github.com/replaygaming/rspec-simplecov, specifically it's https://github.com/replaygaming/rspec-simplecov/blob/master/lib/rspec/simplecov/setup.rb#L27-L35 that's the meat of the matter as far as this question is concerned.

What the gem does is to inject a new RSpec test in the after suite callback. That test gets the result from SimpleCov and compares it against the minimal coverage set for SimpleCov.

My problem is that the result I get back is always empty (and hence always has 100% coverage). I tried creating a result object manually by getting the Coverage.result and creating a new SimpleCov result object based on it. I can see that the original result has a lot of data and that it has data for the specs run and the files tested by the specs, but the result data is still nil. No files, no lines, no nothing and 100% coverage ...

Anyone want to have a stab at why that might be or maybe suggest another way of solving the same problem?

Many thanks for your time either way :)

/Jonas

jonas.schube...@gmail.com

unread,
Sep 14, 2015, 5:51:01 AM9/14/15
to SimpleCov
After running further tests I found that the test coverage was always 100% 0/0 files covered.

So some debugging later (commenting out things in the gem to see when the error went away) I found the issue.

The gem required simplecov, since it needs it. The problem is that simplecov looks at the last thing that required it as the "source" for further coverage monitoring. So the main project includes simplecov and then the rspec-simplecov gem that also includes simplecov. Simplecov looks at the files from THE GEM when determining the coverage.

Solution was simple, just don't require simplecov in the gem, the main project should include it anyway (and now it's required to).

Simple fix, working fine now...

Reply all
Reply to author
Forward
0 new messages