Integrating CodeShip With Coveralls for Code Coverage Reports

2 minute read

About Coveralls

Coveralls is an automated code coverage service. Starting with Coveralls and CodeShip is fast and easy.

By using Coveralls you can help enforce higher standards of code quality and transparency with your engineering team.

Their documentation does a great job of providing more information, in addition to the setup instructions below.

Coveralls Discount Code

Thanks to our partnership with Coveralls we can provide a 25% Discount for 3 months. Use the code "coverallslovescodeship" and get started right away.

Setup For Other Languages

Coveralls supports a lot of other languages. Check out their fantastic documentation.

CloudBees CodeShip Pro

Setting Your Variables

To start, you 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 be building 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 to 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

CloudBees CodeShip Basic

Setting Your Variables

To start, you need to 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.

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']}"

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