Ruby

Code Coverage

Example

For a full working example, see our example Ruby repository.

Details

1

Install and instrument test coverage with SimpleCov

2

Configure SimpleCov to generate JSON reports:

1require 'simplecov'
2require 'simplecov_json_formatter'
3SimpleCov.start do
4 formatter SimpleCov::Formatter::JSONFormatter
5 add_filter '/spec/'
6end

If you want to combine the JSON format with other formats, use SimpleCov’s MultiFormatter:

1SimpleCov.start do
2 formatter SimpleCov::Formatter::MultiFormatter.new([
3 SimpleCov::Formatter::JSONFormatter,
4 SimpleCov::Formatter::HTMLFormatter
5 ])
6 add_filter '/spec/'
7end
3

Publish SimpleCov’s JSON coverage reports using qlty coverage publish PATH

SimpleCov will write a coverage data file to coverage/coverage.json.

This path is needed to complete the final step which is publishing this data to qlty.

For GitHub Actions users, the simplest next step is to use our example workflow from our example ruby repository.

Otherwise, refer to:

Compatibility

SimpleCov version 0.22.0+

(We may be compatible with older versions of SimpleCov, but they have not been explicitly tested.)