Deprecated
This repository is no longer maintained. As an alternative, check codacy-coverage-reporter to send your test coverage results to your Codacy dashboard.
ruby-codacy-coverage
Ruby coverage reporter for Codacy https://www.codacy.com
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.