Uso de Travis

Step one: Sign in

To get started with Travis CI, sign in through GitHub OAuth. Go to Travis CI and follow the Sign In link at the top.

GitHub will ask you to grant read and write access. Travis CI needs write access for setting up service hooks20.1 for your repositories when you request it, but it won't touch anything else.

Step two: Activate GitHub Service Hook

Once you're signed in go to your profile page. You'll see a list of your repositories.

Flip the on/off switch for each repository that you want to hook up on Travis CI.

Step three: Install the travis gem

The travis gem includes both a command line client and a Ruby library to interface with a Travis CI service. Véase Travis en la Línea de Comandos 20.6.

Add .travis.yml file to your repository

In order for Travis to build your project, you need to tell the system a little bit about it.

To do so, add .travis.yml to the root of your repository.

  1. The most important one is the language key. It tells Travis what builder to pick.
  2. Ruby projects typically use different build tools and practices than Clojure or PHP projects do, so Travis needs to know what to do.
  3. If .travis.yml is not in the repository, is misspelled or is not valid YAML, will ignore it, assume Ruby as the language and use default values for everything.

[~/srcLPP/coro/frac(master)]$ cat .travis.yml 
language: ruby
  - 1.9.3
  - jruby-18mode # JRuby in 1.8 mode
  - jruby-19mode # JRuby in 1.9 mode
  - rbx-18mode
  - rbx-19mode
  - 1.8.7

Validate Your .travis.yml

The travis gem includes both a command line client and a Ruby library to interface with a Travis CI service.

Inside a repository with .travis.yml

[~/sinatra/sinatra-number_cruncher(master)]$ travis lint 
Hooray, .travis.yml looks valid :)
travis-lint will check things like

  1. The .travis.yml file is valid YAML
  2. The language key is present
  3. The runtime versions (Ruby, PHP, OTP, etc) specified are supported in the Travis CI Environment
  4. That you are not using deprecated features or runtime aliases and so on.

Step four: Trigger Your First Build With a Git Push

Once GitHub hook is set up, push your commit that adds .travis.yml to your repository.

That should add a build into one of the queues on Travis CI and your build will start as soon as one worker for your language is available.

To start a build commit and push something to your repository

Default Test Script

Travis will use Bundler to install your project's dependencies and run rake by default to execute your tests.

Please note that you need to add rake to your Gemfile (adding it to just :test group should be sufficient).

group :development, :test do
  gem "rake"
Groups can be ignored by bundle at install-time (using --without=GROUP1[ GROUP2...]).

[~/srcLPP/coro/frac(master)]$ cat Gemfile 
source ''

gem 'rake'
gem 'rspec'

Exclude non-essential gems like ruby-debug from your Gemfile.

Testing Against Multiple Versions of Gems

Many projects need to be tested against multiple versions of Rack, Event::Machine, HAML, Sinatra, Ruby on Rails, you name it. You can do it with Travis CI. See the manual pages.
  1. Create a directory in your project's repository root where you will keep gemfiles (./gemfiles is a commonly used name)
  2. Add one or more gemfiles to it
  3. Instruct Travis CI to use those gemfiles using the gemfile option in your .travis.yml
      - Gemfile
      - gemfiles/eventmachine-pre

Custom Bundler arguments and Gemfile locations

You can specify a custom Gemfile name:

gemfile: gemfiles/
Unless specified, the worker will look for a file named Gemfile in the root of your project.

You can also set extra arguments to be passed to bundle install:

bundler_args: --without=development


john@exthost:~/291012/frac$ rake -T
rake spec     # Run RSpec code examples
rake specman  # Run rspec with --format documentation
rake thtml    # Run rspec with format: html

john@exthost:~/291012/frac$ cat Rakefile 
$:.unshift File.dirname(__FILE__) + 'lib'

require 'rspec/core/rake_task'
task :default => :spec

desc "Run rspec with --format documentation"
task :specman do
  sh "rspec -Ilib spec/frac_spec.rb --format documentation"

desc "Run rspec with format: html"
task :thtml do
  sh "rspec -Ilib spec/frac_.rb --format html > index.html"
Véase la documentación de la clase RSpec::Core::RakeTask.

john@exthost:~/291012/frac$ rake
/usr/local/ruby/bin/ruby -S rspec ./spec/frac_spec.rb

Finished in 0.00451 seconds
20 examples, 0 failures

Ejemplo de Jerarquía

[~/srcLPP/coro/frac(master)]$ tree -A
|-- Gemfile
|-- Rakefile
|-- lib
|   `-- fraction.rb
`-- spec
    `-- frac_spec.rb

2 directories, 5 files

Página de Travis Mostrando los Resultados de unas Pruebas con Rspec

Figura: Página de Travis Mostrando los Resultados de unas Pruebas con Rspec

Casiano Rodriguez León 2015-01-07