Auto-retry `bundle install` when Travis runs tests

`bundle install` doesn't always work -- sometimes it runs into errors
making HTTP requests, for whatever reason. This will cause Travis to
fail which is pretty annoying.

* Travis supplies an executable called `travis_retry` which will
  automatically retry the command up to 3 times before really failing.
  Tell Travis to use this when it runs `bundle install` before it
  runs tests.
* In spec_helper, we create a Rails app and use this within the
  test suite. This will also run `bundle install`. Unfortunately we
  can't use `travis_retry` for this as it's a function and is not
  available to us in Ruby-land, so use our own retry logic.
This commit is contained in:
Elliot Winkler 2013-10-23 14:18:52 -06:00
parent 803c06b0b0
commit 4440445baf
2 changed files with 28 additions and 5 deletions

View File

@ -1,7 +1,6 @@
script: "bundle exec rake spec cucumber"
install:
"bundle install"
install: "travis_retry bundle install"
rvm:
- 1.9.2

View File

@ -1,10 +1,34 @@
# Create Rails environment based on the version given from Appraisal
TESTAPP_ROOT = File.join(File.dirname(__FILE__), '..', 'tmp', 'aruba', 'testapp')
FileUtils.rm_rf(TESTAPP_ROOT) if File.exists?(TESTAPP_ROOT)
`rails new #{TESTAPP_ROOT}`
ENV['RAILS_ENV'] = 'test'
FileUtils.rm_rf(TESTAPP_ROOT) if File.exists?(TESTAPP_ROOT)
`rails new #{TESTAPP_ROOT} --skip-bundle`
ENV['RUBYOPT'] = ""
Dir.chdir(TESTAPP_ROOT) do
retry_count = 0
loop do
puts "Current directory: #{Dir.pwd}"
%w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |key|
puts "#{key}: #{ENV[key].inspect}"
end
command = 'bundle install'
output = Bundler.with_clean_env { `#{command} 2>&1` }
if $? == 0
break
else
retry_count += 1
if retry_count == 3
raise "Command '#{command}' failed:\n#{output}"
end
end
end
end
ENV['BUNDLE_GEMFILE'] ||= TESTAPP_ROOT + '/Gemfile'
ENV['RAILS_ENV'] = 'test'
require "#{TESTAPP_ROOT}/config/environment"
require 'bourne'