One of my jobs this week was to get my Ruby implementation of Tic Tac Toe up and running on Travis CI, “a hosted continuous integration service for the open source community”. What that means in plain English is that every time I push up to Github, Travis CI can automatically run all of my tests against various run times (MRI, JRuby, Rubinious) that I might not even have installed locally and then I can either watch the tests run live on their website or just wait for an email telling me if my app is fixed or broken— pretty awesome, right?!?

Getting this up and running was pretty straightforward, but I did spend a good amount of time bouncing around a few online guides and testing/tweaking some configuration so I’ll share a few tips and tricks here.

The Travis CI “Getting Started” page does a pretty great job and walks you through the first two steps of signing-in and activating the Github service hook. The next step is adding a file named .travis.yml to the root level of your local repository, and here’s a place where I played with the configuration. In the end I decided to go with a file that just contains:

rvm:
 - 1.9.2
 - jruby-19mode
script: rspec spec

Travis CI uses RVM to manage the rubies I want to test it in so the first three lines just tell Travis CI to test it using Ruby 1.9.2 and JRuby using 1.9.x mode. The final line tells Travis to use ‘rspec spec’ to run all my tests since I’m not using 'rake’, which is the Travis default.

However, if I decided I did want to use rake then I wouldn’t need to use the 'script: rspec spec’ line, but I would need to include a file called Rakefile (also at the root level of my app) that looked like this:

task :default => [:spec]
desc 'run Rspec specs'
task :spec do
  sh 'rspec spec'
end
  • tip of the hat to 8th Light'er Josh Cheek’s tic-tac-toe app for helping me figure out the sh 'rspec spec’ line.

Last, but not least, you also need to include a Gemfile. I’d only been running this app locally with my global gemset so the idea of including a Gemfile for a straight Ruby app seemed totally foreign to me. However, considering that Travis CI needs to know what gems are necessary for your app it makes perfect sense to include it. My Gemfile (also at the root level of the app) looks like this:

source :rubygems
gem "bundler"  , "~> 1.1.3"
gem "rspec"    , "~> 2.8.0"
gem "rake"     , "~> 0.9.2.2" #included if using rake

And now I have a green build using both 1.9.2 and JRuby up at Travis CI, and an inbox full of emails starting with [Fixed] and [Broken] as I tested out the different configurations. Travis CI is an invaluable open source tool and I definitely see myself using it quite a bit. It also supports Clojure, Java, Python, PHP and a host of other languages. I recommend checking it out.