#!/usr/bin/env ruby require 'optparse' require 'ostruct' RUBY_VERSIONS = %W[1.8.7 1.9.2] RAILS_VERSIONS = %W[2.3 3.0 3.1 3.2] DB_ADAPTERS = %W[postgresql mysql mysql2 sqlite3] o = OpenStruct.new o.ruby_versions = RUBY_VERSIONS o.rails_versions = RAILS_VERSIONS o.db_adapters = DB_ADAPTERS - ["mysql"] OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options]" opts.on("-n", "--dry-run", "Do a dry run without executing actions") do |v| o.dry_run = true end opts.on("--update", "Update gem dependencies") do |v| o.update = v end opts.on("--install", "Install gem dependencies") do |v| o.install = v end opts.on("--db adapter", String, "Choose which db adapter(s) to run. Default is: #{o.db_adapters.join(' ')}" ) do |adapter| o.db_adapters = adapter.split end opts.on("--ruby version", String, "Choose which version(s) of ruby to run. Default is: #{o.ruby_versions.join(' ')}") do |ruby| o.ruby_versions = ruby.split(' ') end opts.on("--rails version", String, "Choose which version(s) of rails to run. Default is: #{o.rails_versions.join(' ')}") do |rails| o.rails_versions = rails.split(' ') end opts.on("--full", "run complete matrix of ruby, rails, and db") do o.ruby_versions = RUBY_VERSIONS o.rails_versions = RAILS_VERSIONS o.db_adapters = DB_ADAPTERS end opts.on("--quick", "quick run on Postgres, ruby #{RUBY_VERSIONS.last} and rails #{RAILS_VERSIONS.last}") do o.ruby_versions = [RUBY_VERSIONS.last] o.rails_versions = [RAILS_VERSIONS.last] o.db_adapters = ["postgresql"] end end.parse! Combo = Struct.new(:ruby, :rails, :db_adapter) if o.update or o.install o.db_adapters = [nil] end combos = o.ruby_versions.product(o.rails_versions, o.db_adapters).map{|product| Combo.new(*product)}.select {|combo| case when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false else true end } GEMFILES_DIR = File.expand_path('../gemfiles', __FILE__) errs = [] combos.each_with_index do |combo, n| ruby = combo.ruby rails = combo.rails db_adapter = combo.db_adapter cmd = case when o.update "bundle update" when o.install "bundle install" else "bundle exec rake #{db_adapter}:spec" end command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}" rvm #{ruby} do #{cmd}} puts "\n\n*** ruby version #{ruby} - rails version #{rails} - db adapter: #{db_adapter} [#{n+1} of #{combos.size}]\n\n#{command}" next if o.dry_run system(command) or errs << "ruby #{ruby}, rails #{rails}#{db_adapter && ", db_adapter #{db_adapter}"}" end puts errs.any? ? "\n*** #{errs.size} failures:\n\t#{errs.join("\n\t")}" : "\n*** #{combos.size > 1 ? 'all versions' : 'spec'} succeeded ***" unless o.dry_run