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.
Prerequisites
- 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'
How to Upload:
- Run your test suite with the commands you normally would.
- Navigate to the root project directory in your terminal.
- 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!