Skip to content
Browse files

new ci script for travis

  • Loading branch information...
1 parent df6ae04 commit 836f3d5f43269197563a64ff1fdae7c264a6639d @mislav committed Jul 29, 2011
Showing with 46 additions and 24 deletions.
  1. +2 −10 .travis.yml
  2. +6 −14 Rakefile
  3. +38 −0 test/ci.rb
View
12 .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
View
20 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
@@ -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
View
38 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.
Something went wrong with that request. Please try again.