Adding Codecov to a Ruby Project

Photo by Luca Bravo on Unsplash

I was having trouble figuring out how to add Codecov to a ruby gem I was developing and testing with Rspec. So I wanted to write this guide to help show how to add Simplecov and upload your results to Codecov.

  • Codecov Account (Sign Up — Codecov)
  • Codecov Enabled for Your Repo
  • Once you have this grab your Codecov Repository Upload token at:
https://app.codecov.io/{your-git-provider}/{your-git-username/{repo-name}/settings
  • A project with Test Results you want to upload.

In your Gemfile:

gem 'simplecov-cobertura', require: false, group: :testgem 'codecov', require: false, group: 'test'

Require Statements in your Spec File:

require 'simplecov'SimpleCov.startrequire 'simplecov-cobertura'SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatterrequire 'codecov'require 'file_to_test.rb'
  1. Run your test suite with the commands you normally would.
  2. Navigate to the root project directory in your terminal.
  3. Run the following code:
bash <(curl -s https://codecov.io/bash) -t {your token here}

4. If everything went right you should see feedback about a successful upload in your terminal.

You can now view your data at https://codecov.io/. I also like adding a badge to the git repository from Shields.io: Quality metadata badges for open source projects. They have a few different options for Codecov Badges

That’s it!

I'm a Software Developer out of Portland, Oregon. I like writing Ruby code, photography, and learning continuously. Website at https://ajm.codes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store