Integrating Coveralls with Codeship

Written by: Kelly Andrews
3 min read
Stay connected

At Codeship, we’re pleased to be able to integrate with several third-party products across a variety of areas to ensure your CI/CD workflows are that much smoother. For example, Coveralls is an automated code-coverage service, and getting started with Coveralls and Codeship is fast and easy.

Of course, their documentation does a great job of providing more information for the wide variety of languages it supports, but this post will walk you through setting up Coveralls with Codeship. Let's start with the setup for Codeship Pro.

Coveralls and Codeship Pro

To begin, you'll need to add your Coveralls repo token to the encrypted environment variables that you encrypt and include in your codeship-services.yml file.

Coveralls gem

Next, you’ll want to either manually install the Coveralls gem in your Dockerfile or add it to the Gemfile that you install your dependencies from in your Docker image build.

gem 'coveralls', require: false

Note that this will require you to build an image that contains both Ruby and Rubygems. If the image does not contain both of these, you will be unable to install the necessary coveralls gem.

Project configuration

Now, you’ll need to put the Coveralls initializers into your spec_helper.rb or env.rb file, depending on which framework you use.

require 'coveralls'
Coveralls.wear!

If you want to combine the coverage data from different frameworks, add the following to your spec_helper.rb or env.rb.

# Coveralls with Rspec and Cucumber
require 'coveralls'
Coveralls.wear_merged!
SimpleCov.merge_timeout 3600
# MAKING SURE SIMPLECOV WORKS WITH THE PARALLEL_TESTS GEM
SimpleCov.command_name "RSpec/Cucumber:#{Process.pid.to_s}#{ENV['TEST_ENV_NUMBER']}"

Finally, you’ll you need to add a rake task that pushes your coverage report as soon as your build is finished.

require 'coveralls/rake/task'
Coveralls::RakeTask.new

Pushing data

The last thing you’ll need to be sure to do is actually push your data out to Coveralls. This will happen with a command either run directly or inside of a script in your codeship-steps.yml file:

- name: coveralls_push
  service: your_service
  command: bundle exec rake coveralls:push

Coveralls and Codeship Basic

To begin, add your Coveralls repo token to a .coveralls.yml file to your codebase that contains your Coveralls key:

repo_token: YOUR_COVERALLS_TOKEN

It is also possible to set this in the environment variables for your project. You can do this by navigating to Project Settings and then clicking on the Environment tab.

Coveralls gem

Next, you’ll need to require the gem in your Gemfile.

gem 'coveralls', require: false

Project configuration

Now, you’ll need to put the Coveralls initializers into your spec_helper.rb or env.rb file, depending on which framework you use.

# Coveralls with Rspec and Cucumber
require 'coveralls'
Coveralls.wear_merged!
SimpleCov.merge_timeout 3600
# MAKING SURE SIMPLECOV WORKS WITH THE PARALLEL_TESTS GEM
SimpleCov.command_name "RSpec/Cucumber:#{Process.pid.to_s}#{ENV['TEST_ENV_NUMBER']}"

Then you need to add a rake task that pushes your coverage report as soon as your build is finished.

require 'coveralls/rake/task'
Coveralls::RakeTask.new

Pushing data

To push the data to Coveralls, add the following after your test commands on Codeship:

bundle exec rake coveralls:push

Thanks to our partnership with Coveralls, we can provide a 25 percent discount for three months. Use the code coverallslovescodeship and get started right away.

Stay up to date

We'll never share your email address and you can opt out at any time, we promise.

Loading form...
Your ad blocker may be blocking functionality on this page. Please disable for an improved experience.