With the Gem pullreview-coverage, you can retrieve your Ruby test coverage into PullReview.

How does it work?

The idea is to add a Gem and configure it to collect the coverage reports, and then to submit them to PullReview just after the tests are completed. PullReview will process them and map them to the current review, and add actions for the uncovered methods/classes.

Depending on race conditions between PullReview and your CI-Server, you will have reviews with or without coverage related actions. If you have multiple test- suites, running on multiple nodes, PullReview will merge the coverage reports. If PullReview isn't available at report submission time, note that the build won't fail.

Setup your project

Update Gemfile for :test

Add the following in :test group.

group :test do
  gem 'pullreview-coverage', require: false

Once done, run a bundle install and commit your modified Gemfile and Gemfile.lock.

Note: this Gem is open-source and available via RubyGems.


If you don't already use simplecov

You can simply enable the coverage report by adding the following lines in your {spec,test}_helper.rb:

require 'pullreview/coverage_reporter'

If you use already simplecov

Add our formatter in your {spec,test}_helper.rb:

require 'simplecov'
require 'pullreview/coverage'
formatters = []
... # your other formatters (html ?)
formatters << PullReview::Coverage::Formatter
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]

Retrieve your PullReview Token

There are two ways to find your PullReview Token.

  1. For private repos, in any code review, cliking on the link Badge urls, uncollapses the link for your badge. The token in that link is the one you're looking for.

  2. In the page where you set up your repositories, beside the repositories under review, you'll find a little list icon. Click on the icon to see a list of documentation related to your repository. Click on How to enable test coverage for this repository. You'll then browse documentation similar to this one but in which your token is displayed in the section "Setup in your CI build".

Setup in your CI build

Add an environment variable with your repository token

PULLREVIEW_REPO_TOKEN=<your repo token> rake test

Depending on the CI you use, you can pass that token via the environment variable PULLREVIEW_REPO_TOKEN, prefer the encrypted option if available:

Finally, trigger a build

If the Gemfile modification is merged in your integration branch, new actions about test coverage will now be reported in the corresponding review.

FAQ and Miscellaneous

You'll find more information on the Gem homepage.