Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created August 28, 2012 01:57
Show Gist options
  • Select an option

  • Save kenmazaika/3494240 to your computer and use it in GitHub Desktop.

Select an option

Save kenmazaika/3494240 to your computer and use it in GitHub Desktop.
Parallel Test Helper Tasks
# This code taken from code written by Jack Thorne.
namespace :test do
desc "test the same tests with rake using parallel (can also run :units and :functionals)"
task :fast => :environment do
ENV['test']
ENV['TEST_ENV_NUMBER']='2'
begin
ActiveRecord::Base.establish_connection Rails.configuration.database_configuration['test']
ActiveRecord::Base.connection.instance_values["config"][:database]
if ActiveRecord::Migrator.get_all_versions.last == ActiveRecord::Migrator.current_version
Rake::Task['parallel:test'].execute pattern: '^test/(unit|functional)'
else
Rake::Task['test:fast:migrate'].execute
end
rescue
Rake::Task['test:fast:prepare'].execute
end
end
namespace :fast do
task :units => :environment do
Rake::Task['parallel:test'].execute pattern: '^test/unit'
end
task :functionals => :environment do
Rake::Task['parallel:test'].execute pattern: '^test/functional'
end
task :prepare => :environment do
puts "I see it's your first time! let me help you out"
%w[parallel:create parallel:prepare parallel:seed].each { |task| Rake::Task[task].execute }
puts 'You are all set! run "rake test:fast" to run all tests in parallel'
end
task :migrate => :environment do
puts 'your parallelization is dated. [beep beep boop]'
Rake::Task['parallel:migrate'].execute
puts '[beeee boop beep] systems ready...'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment