Last Updated: February 25, 2016
·
7.144K
· weimeng

Using Code Climate's new test reporter together with Coveralls and SimpleCov's HTML Formatter

Code Climate just announced the addition of test coverage reporting to their suite of code quality tools. Exciting!

As I expected, Code Climate's codeclimate-test-reporter gem was using SimpleCov to power their test coverage reporting.

At work, we're already using Coveralls to track test coverage over time. In addition, I'm using SimpleCov's HTMLFormatter to generate local test coverage reports so I don't have to wait on our CI provider for coverage reports.

Thankfully, it was fairly simple to add Code Climate's own formatter into my SimpleCov workflow.

Add codeclimate-test-reporter to your Gemfile and at the top of spec_helper.rb:

require 'codeclimate-test-reporter'
require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
  Coveralls::SimpleCov::Formatter,
  SimpleCov::Formatter::HTMLFormatter,
  CodeClimate::TestReporter::Formatter
]
SimpleCov.start 'rails'

Done!

You can also find any updates to the code here: https://gist.github.com/weimeng/6290044

2 Responses
Add your response

I used webmock for mocking external requests, so I had a problem with it blocking coveralls and codeclimate from submitting the reports, so I added this in:

RSpec.configure do |config|
  ...
  config.after(:suite) do
    WebMock.disable!
  end
end

In addition, I amended your code such that only if the ENV variable is provided for the respective services do I add it to the formatter. See gist: https://gist.github.com/jaryl/6554599#file-spec_helper-rb

over 1 year ago ·