Please note that SimpleCov only supports Ruby 1.9 and later.
You shouldn't need more than a quick change to get your project on Coveralls. Just include coveralls-ruby in your project's Gemfile like so:
# ./Gemfile gem 'coveralls', require: false
While SimpleCov only supports Ruby 1.9+, using the Coveralls gem will not fail builds on earlier Rubies or other flavors of Ruby.
coveralls-ruby uses an optional
.coveralls.yml file at the root level of your repository to configure options.
repo_token (found on your repository's page on Coveralls) is used to specify which project on Coveralls your project maps to.
Another important configuration option is
service_name, which indicates your CI service and allows you to specify where Coveralls should look to find additional information about your builds. This can be any string, but using the appropriate string for your service may allow Coveralls to perform service-specific actions like fetching branch data and commenting on pull requests.
Example: A .coveralls.yml file configured for Travis Pro:
repo_token from the command line:
COVERALLS_REPO_TOKEN=asdfasdf bundle exec rspec spec
After configuration, the next step is to add coveralls-ruby to your test suite.
For a Ruby app:
# ./spec/spec_helper.rb # ./test/test_helper.rb # ..etc.. require 'coveralls' Coveralls.wear!
For a Rails app:
require 'coveralls' Coveralls.wear!('rails')
Coveralls.wear! must occur before any of your application code is required, so it should be at the very top of your
And holy moly, you're done!
"But wait!" you're saying, "I already use SimpleCov, and I have some custom settings! Are you really just overriding everything I've already set up?"
Good news, just use this gem's SimpleCov formatter directly:
require 'simplecov' require 'coveralls' SimpleCov.formatter = Coveralls::SimpleCov::Formatter SimpleCov.start do add_filter 'app/secrets' end
Or alongside another formatter, like so:
require 'simplecov' require 'coveralls' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ] SimpleCov.start
If you're using more than one test suite and want the coverage results to be merged, use
Coveralls.wear_merged! instead of
Or, if you're using Coveralls alongside another SimpleCov formatter, simply omit the Coveralls formatter, then add the rake task
coveralls:push to your
Rakefile as a dependency to your testing task, like so:
require 'coveralls/rake/task' Coveralls::RakeTask.new task :test_with_coveralls => [:spec, :features, 'coveralls:push']
Unless you've added
coveralls:push to your default rake task, your build command will need to be updated on your CI to reflect this, for example:
bundle exec rake :test_with_coveralls
Read more about SimpleCov's result merging.
coveralls-ruby also allows you to upload coverage data manually by running your test suite locally.
To do this with RSpec, just type
bundle exec coveralls push in your project directory.