Skip to content
Post coverage results to Codacy
Branch: master
Clone or download
rtfpessoa Merge pull request #39 from codacy/mrfyda-patch-1
Add GitLab CI commit env variable
Latest commit 6e71f39 Sep 20, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add issue template Aug 20, 2016
lib Add GitLab CI commit env variable Sep 20, 2018
scripts Remove ruby 1.9.3 from circle ci script Aug 10, 2018
spec
.gitignore Fix HTTP usage Oct 20, 2016
Gemfile Update versions and compatibility for 1.9 Dec 1, 2016
Gemfile.ruby-19 Update versions and compatibility for 1.9 Dec 1, 2016
README.md Update README.md. May 11, 2017
circle.yml Remove ruby 1.9.3 from circle ci build Aug 10, 2018
codacy-coverage.gemspec Update gemspec to depend on ruby 2.0 or after Aug 10, 2018

README.md

ruby-codacy-coverage

Ruby coverage reporter for Codacy https://www.codacy.com

Codacy Badge Codacy Badge Build Status Gem Version

Parses SimpleCov output and submits the result to Codacy

Setup

Include the gem in your project

gem 'codacy-coverage', :require => false

In the first line of your spec_helper initialize the reporter:

require 'codacy-coverage'

Codacy::Reporter.start

Configuration

To update Codacy, you will need your project API token. You can find the token in Project -> Settings -> Integrations -> Project API.

Then set it in your terminal, replacing %Project_Token% with your own token:

export CODACY_PROJECT_TOKEN=%Project_Token%

Enterprise

To send coverage in the enterprise version you should:

export CODACY_BASE_API_URL=<Codacy_instance_URL>:16006

By default this plugin will not submit results if you run your tests in localhost. If you want to force the submission you can setup the following environment variable:

export CODACY_RUN_LOCAL=true

Note: You should keep your API token well protected, as it grants owner permissions to your projects.

Running Tests

When you run your tests, the plugin will send the coverage info to Codacy.

For example, run the following commands:

gem install bundler
bundle install

This will install the required dependencies. Then just run the tests:

bundle exec rspec

By default, the debug info will be logged into a file. If you want the debug info to be printed to stdout you can:

export DEBUG_STDOUT=true

You can now check your coverage results in the Codacy dashboard of your project.

Troubleshoot

Cannot send coverage when using VCR

require 'vcr'
VCR.configure do |config|
  # other config options
  config.allow_http_connections_when_no_cassette = false
  config.ignore_hosts 'api.codacy.com'
end

Cannot generate local simplecov report

Override SimpleCov.formatter by adding both your prefered simplecov formatter and Codacy's formatter. You can also add more options to SimpleCov.start.

require 'simplecov'
require 'codacy-coverage'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
    SimpleCov::Formatter::HTMLFormatter,
    Codacy::Formatter
])

SimpleCov.start do
  add_filter '.gems'
  add_filter 'pkg'
  add_filter 'spec'
  add_filter 'vendor'
end

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features:

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

You can’t perform that action at this time.