runspecs in schema_associations-0.1.2 vs runspecs in schema_associations-1.0.0

- old
+ new

@@ -1,23 +1,30 @@ #!/usr/bin/env ruby require 'optparse' require 'ostruct' +require 'shellwords' +require 'tempfile' -PROJECT = File.basename(File.expand_path('..', __FILE__)) +RUBY_VERSIONS = %W[1.9.2 1.9.3] +RAILS_VERSIONS = %W[3.2] -RUBY_VERSIONS = %W[1.8.7 1.9.2] -RAILS_VERSIONS = %W[2.3 3.0 3.1] - o = OpenStruct.new o.ruby_versions = RUBY_VERSIONS o.rails_versions = RAILS_VERSIONS -o.run_cmd = "rake spec" 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("--ruby version", String, "Choose which version(s) of ruby to run. Default is: #{o.ruby_versions.join(' ')}") do |ruby| @@ -31,28 +38,53 @@ opts.on("--quick", "quick run ruby #{RUBY_VERSIONS.last} and rails #{RAILS_VERSIONS.last}") do o.ruby_versions = [RUBY_VERSIONS.last] o.rails_versions = [RAILS_VERSIONS.last] end + opts.on("--rspec", "run rspec rather than rake") do |v| + o.rspec = v + end + end.parse! -cmds = if o.install - ['bundle update'] - else - ['bundle update --local rails | grep rails', o.run_cmd] - end -n = 1 -total = o.ruby_versions.size * o.rails_versions.size -o.ruby_versions.each do |ruby| - o.rails_versions.each do |rails| - puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n} of #{total}]\n\n" - n += 1 - allcmds = [] - allcmds << "rvm use #{ruby}" - allcmds << "export #{PROJECT.upcase}_RAILS_VERSION=#{rails}" - allcmds += cmds - allcmds << 'exit' - system %Q{echo '#{allcmds.join(' \n ')}' | bash -i} or abort "aborting #{$0}" +Combo = Struct.new(:ruby, :rails) + +combos = o.ruby_versions.product(o.rails_versions).map{|product| Combo.new(*product)}.select {|combo| + case + when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false + else true end -end +} + +GEMFILES_DIR = File.expand_path('../gemfiles', __FILE__) +errs = [] +combos.each_with_index do |combo, n| + ruby = combo.ruby + rails = combo.rails + + cmd = case + when o.update + "bundle update" + when o.install + "bundle install" + when o.rspec + "bundle exec rspec" + else + "bundle exec rake spec" + end + + command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}" rvm #{ruby} do #{cmd} #{Shellwords.join(ARGV)}} + + puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n+1} of #{combos.size}]\n\n#{command}" + + next if o.dry_run + + Tempfile.open('runspecs') do |file| + system("(#{command}) 2>&1 | tee #{file.path}") + file.rewind + errs << "ruby #{ruby}, rails #{rails}" if file.readlines.grep(/^Failed examples/).any? + end +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 +exit !errs.any?