How To Get Accurate Test Coverage With SimpleCov, Spring, and Rails
If you’d like to read more about how I figured this out, I’ve written a longer blog post that goes into a lot more detail: How I Figured Out A Test Coverage Issue With SimpleCov And Spring.
The following code has been tested with these library versions:
spring from being automatically required:
Configure Spring and monkey-patch SimpleCov:
Add this code to
Add this code to the top of
Add these lines to the top of
That’s it! Now you should see accurate test coverage whenever you run your RSpec tests with Spring.
I am planning to open an SimpleCov issue to get some feedback about this approach, and it would be great SimpleCov and Spring just worked together by default. In the meantime, you can use this code to get things working.
If you’d like to learn more about how I investigated this issue, you can check out this longer write-up that goes into a lot more detail: How I Figured Out A Test Coverage Issue With SimpleCov And Spring.