Travis CI setup
This recipe should help you create a .travis.yml
file that meets all
the following criteria (which the default configuration does not):
-
If necessary, unencrypt the secrets file
config/application.yml
from the encryptedconfig/application.yml.asc
(assuming you’re following the methodology described in this post for managing secrets). -
Correctly run both RSpec specs and Cucumber scenarios, and merge the coverage results (by default, you’d only see coverage data for whichever set of tests is run last). NOTE: The below file uses Cucumber options that cause the test run to fail if there are undefined steps as well as if there are failing steps. This setting is appropriate for a production repo.
-
Push the merged coverage results to CodeClimate, allowing the use of a CodeClimate coverage badge for the repo.
Prerequisites
You should have:
-
A CodeClimate account configured to do code analysis on your repo. Log in to that account and grab the value of your CodeClimate Test Reporter ID–you will need it in the below setup.
-
A Travis CI account configured to do builds on your project. Log in to that account and set the environment variable
CCKEY
to the value of your CodeClimate Test Reporter ID.
What to do
Make sure your .travis.yml
is checked into version control and
mostly matches the following.
The line that refers to
config/application.yml
assumes that you are using
this recipe
to manage sensitive data such as API keys; if you’re not, you should
comment out that line and replace it with whatever commands are
necessary (if any) to give Travis CI access to such information.
Now, when you push to a branch, your Travis build will collect and report coverage information to CodeClimate. Note that coverage information isn’t meaningful unless all tests pass.