How to connect your Ruby project to Travis and prepare a Martini in 15 minutes

Original author: Paolo "Nusco" Perrotta
  • Transfer
image
There is a tendency that every Ruby project joins Travis . Travis is a very simple open source system for continuous integration . We are usually too lazy to connect all our projects to automated build testing. Travis allows you to do this in minutes. This is a step-by-step guide on how to connect your project to Travis and prepare a delicious Martini cocktail in about 15 minutes. It should be noted that the preparation of Martini will take about five minutes, so the part about Travis will take 10 minutes of your life.





Make sure that our project has everything you need (2 minutes)


To join Travis, the project needs three prerequisites:
  • This is a ruby ​​project on GitHub.
  • He uses the Bundler to manage gems. (In fact, this is not a limitation, but it greatly facilitates the setup for Travis.)
  • Tests for the project can be run with a simple command. This is usually a rake command , but other commands (say bundle exec rspec spec ) are great too.

It is essential that your project can be tested on a new machine simply by running bundle install before the test team. If the configuration is more complicated, you will have to add additional configs for Travis. In any case, simplifying the installation of your project is a good idea, regardless of whether you will use Travis or not.

I assume that your project meets all three assumptions, and that tests can be run using bundle exec rake test .

Create a Travis configuration file (3 minutes)


Create a .travis.yml file in the root of the project. Here's what mine looks like:

    rvm:           # перечень всех версий Ruby, на которых хотите протестировать
      - 1.9.3
      - jruby
      - rbx
    script: "bundle exec rake test" # команда для запуска тестов


All settings have rational defaults, so your configuration can be even simpler. For example, if you omit the script property , Travis will use bundle exec rake , or just rake if the Bundler is not used. See the Travis documentation for more details .

Activate the project on Travis (2 minutes)


We go to travis-ci.org and log in using your GitHub account. We provide Travis read / write access to your GitHub. Your own Travis token is on the profile page .

image

In fact, do not bother about the token yet - but since you are on the profile page, click on the project switch that will be tested on Travis.

Launch the first build (3 minutes)


Send your changes to your repository git (make sure to commit a file .travis.yml ), then go to the main Travis , sit back and watch as Travis adds your project builds in turn, sets the bundle and runs tests. When the build is completed, check the mail, there you will see a love message from Travis - and congratulations that everything is green (well, or red)!

If interesting...


Why does Travis need read access to your GitHub account? Then, that Travis automatically configures GitHub to notify him that you are pushing into the project. If you want, check: on the project administration page in GitHub - Service Hooks - click on the Travis hook . The configuration will look like this:

image

If you click Test Hook , Travis will schedule the build right now.

Cooking Martini (5 minutes)


image
Fill a frozen cocktail glass with cold gin, add a little vermouth and mix. Garnish with olive.

(If in a hurry, you can combine this step with the previous one, which will save you three minutes while Travis is busy building your project)

Drink Martini (extra time)


I don’t think my help is needed here. Find a good company and have fun. But do not drink much!

Also popular now: