Question

I am trying to use the simplecov gem in a Ruby project. However I have failed miserably. Here is what I've done until now.

My project structure is: ProjectFolder - lib - test

I have my tests in test and source code in lib. I have created a test_helper.rb in the test directory and added the following.

require 'simplecov'
SimpleCov.start

Then I put `require 'test/test_helper.rb' in every test file. What happened was it sometimes created some report, and sometimes didn't. And when it did it was inconsistent.

All the tutorials I found was for Rails so I turn to StackOverflow once more, to show me the way.

Was it helpful?

Solution

Rcov/SimpleCov will only report the coverage of the tests ran.

For a full coverage report, you must ensure that the full test suite is ran as the last test, to build a full coverage report.

You will also want to make sure it is the first require in your test_helper.rb file.

From the documentation:

Note: If SimpleCov starts after your application code is already loaded (via require), it won't be able to track your files and their coverage! The SimpleCov.start must be issued before any of your application code is required!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top