Open ThomasOwens opened 1 month ago
I asked about this in a Stack Overflow question and got an answer from mitch_. The solution was, as described, to add SimpleCov.external_at_exit = true
before the SimpleCov.start
in the test_helper.rb
file. I also did have to convert the start to a block and explicitly filter the vendor and test directories.
If this doesn't represent a bug in SimpleCov, it would be worth updating the readme to describe how to integrate SimpleCov with minitest. If there's a more appropriate solution, it would be good to get that out into the world as well.
I was able to put together a very simple repository that demonstrates the issue, including committing the coverage files.
https://github.com/ThomasOwens/simplecov-bug-demo
I'm building a gem, which was initialized using the
bundler gem
tooling. After initializing the gem, I added a dependency on simplecov for development and configured it per instructions. However, when I run commands (likebundle exec rake
, which is configured to run tests and rubocop), I get output, as shown below, that indicates the coverage report is being generated before test execution.At first, I thought it had to do with the initialization of application code before simplecov, but it looks like the only thing being initialized is the standard
version.rb
file. It appears to be a timing of generation versus test based on the console output.In the reproduction example repository, I would expect no coverage of lib/simplecov-bug-demo/version.rb, because this file is required in the gemspec. However, I would expect lines 7-8 of lib/simplecov-bug-demo/commands/command.rb to be covered. However, neither line is covered. Only the module, class, and method declaration lines are covered, which is what I would expect for simply loading the file after executing simplecov.
Without a
.simplecov
file, the console output ofbundle exec rake
looks like:With a
.simplecov
file, the console output ofbundle exec rake
is:I'm using Ruby 3.3 inside a devcontainer built on top of a Ruby 3.3 docker image. Minitest is at version 5.25.1, Rake at 13.2.1, and simplecov at 0.22.0.
The underlying cause may be the same as #1099. However, that issue does talk specifically about Rails, which is not involved in my project.