Skip to content

Commit

Permalink
new ci script for travis
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jul 29, 2011
1 parent df6ae04 commit 836f3d5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
12 changes: 2 additions & 10 deletions .travis.yml
@@ -1,13 +1,5 @@
script: test/ci.rb
rvm:
- 1.8.6
- 1.8.7
gemfile:
- Gemfile
- test/gemfiles/Gemfile.2.2
- test/gemfiles/Gemfile.2.1
- test/gemfiles/Gemfile.2.0
- test/gemfiles/Gemfile.1.2
env:
- DB=sqlite3
- DB=mysql
- DB=postgres
- 1.9.2
20 changes: 6 additions & 14 deletions Rakefile
@@ -1,11 +1,15 @@
require 'rake/testtask'

desc 'Default: run unit tests.'
task :default => [:create_database, :test]
task :default => :test

desc 'Test the will_paginate plugin.'
Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
if ENV['DB'] and ENV['DB'] != 'sqlite3'
t.pattern = %w[test/finder_test.rb]
else
t.pattern = 'test/**/*_test.rb'
end
t.libs << 'test'
end

Expand All @@ -22,15 +26,3 @@ namespace :test do ||
t.libs << 'test'
end
end

desc 'Create necessary databases'
task :create_database do |variable|
case ENV['DB']
when 'mysql', 'mysql2'
`mysql -e 'create database will_paginate;'`
abort "failed to create mysql database" unless $?.success?
when 'postgres'
`psql -c 'create database will_paginate;' -U postgres`
abort "failed to create postgres database" unless $?.success?
end
end
38 changes: 38 additions & 0 deletions test/ci.rb
@@ -0,0 +1,38 @@
#!/usr/bin/env ruby
databases = %w[ sqlite3 mysql postgres ]

def announce(name, msg)
puts "\n\e[1;33m[#{name}] #{msg}\e[m\n"
end

def rails_version(gemfile)
gemfile =~ /\d[\d.]*$/ ? $& : '2.3'
end

if ENV['TRAVIS']
system "mysql -e 'create database will_paginate;' >/dev/null"
abort "failed to create mysql database" unless $?.success?
system "psql -c 'create database will_paginate;' -U postgres >/dev/null"
abort "failed to create postgres database" unless $?.success?
end

gemfiles = ['Gemfile']
gemfiles.concat Dir['test/gemfiles/*'].reject { |f| f.include? '.lock' }

ruby19 = RUBY_VERSION > '1.9'
ruby19_gemfiles = gemfiles.first

bundler_options = ENV['TRAVIS'] ? '--path vendor/bundle' : ''

gemfiles.each do |gemfile|
next if ruby19 and !ruby19_gemfiles.include? gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
if system %(bundle install #{bundler_options})
for db in databases
announce "Rails #{rails_version(gemfile)}", "with #{db}"
ENV['DB'] = db
system %(bundle exec rake)
end
end
end

0 comments on commit 836f3d5

Please sign in to comment.