Continuous-Integration(Ruby-Style)

Chris
Chris
Jul 30, 2017 · 3 min read

Don’t we all feel some fulfillment when we see the green bar on our rockstar projects. I think all projects are rockstar btw, especially the 101 to-do lists we have on out gh profiles.

A Project I recently worked on.

I had a bit of a trial and error first experience with Travis CI so I wanted to note down here how to do it for future projects.

1. Add ‘.travis.yml’ in the root of your project

This will be used by travis-ci when building your project and defines what to test against.

For my project (a command line ruby gem) it looks like this:

language: ruby
rvm:
- 2.2.3

Mine simply says to test against Ruby 2.2.3 but there are a lot more configuration options like setting two versions to test against, e.g

rvm:
- 1.9.3
- 2.2.3

More are available depending on what kind of application you’re testing. See here for more info.

2. Depend on the ‘rake’ gem

Travis CI uses rake to run your tests so you need to require it in your Gemfile. If you want you can only put it in the test group like me or always have it in your app.

group :test do
gem 'rake'
end

3. Make sure your Rakefile has a default task

Travis CI will attempt to run rake to execute your tests. You need to ensure you have a default task which will run all the tests you wish to execute.

Part of my Rakefile for the project looks like this:

require "bundler/gem_tasks"
require "rspec/core/rake_task
RSpec::Core::RakeTask.newtask :default => :spec

Push this all to your project and you’re ready to link Travis to your repository.

4. Ask Travis to test your repository

  1. Visit https://travis-ci.org/ and sign in with github
  • Commit and push something to your repository

NOTE: You cannot trigger your first build using Test Hook button. It has to be triggered by a push to your repository.

5. The icing on the cake — build status images

This is really simple, in your github readme, simply add the following snippet onto your title, like this (if using markdown):

# Billy
[![Build Status](https://travis-ci.org/bigzoo/billy.svg?branch=master)](https://travis-ci.org/bigzoo/billy)

For other README formats or to show build statuses for specific branches see here.

Follow me on Twitter

bigzoo

Little about tech, more about the world.

Chris

Written by

Chris

Lifelong learner. Start-up CTO @snaphubr , Engineer at @andela

bigzoo

bigzoo

Little about tech, more about the world.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade