See untested code in GitLab MRs

Augusts Bautra - Aug 26 - - Dev Community

Today I got a nifty little GitLab feature configured for our Rails project - displaying which lines are lacking spec coverage in MR diff view.
The setup is simple, and I highly recommend you do this also. Works even on the free, self-hosted version!

Here's the official docs, I went down the Cobertura route.

Starting assumptions - you have Simplecov configured and already collecting coverage data in CI runs.

Steps remaining to do:

  1. Add the cobertura formatter
 gem "simplecov-cobertura", require: false
Enter fullscreen mode Exit fullscreen mode
  1. Set up multi-format formatting for Simplecov
  formatters = [
    # The default, human-readable HTML formatter for a coverage report
    SimpleCov::Formatter::HTMLFormatter,   
    # Cobertura XML formatter, for GitLab MRs
    defined?(SimpleCov::Formatter::CoberturaFormatter) ? SimpleCov::Formatter::CoberturaFormatter : nil
  ].compact

  SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters)
Enter fullscreen mode Exit fullscreen mode
  1. Add this configuration to GitLab CI yaml file (adjust the path)
  artifacts:
    reports:     
      coverage_report:
        coverage_format: cobertura
        path: path/to/coverage.xml
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .