lib/parallel_tests/tasks.rb in parallel_tests-1.5.0 vs lib/parallel_tests/tasks.rb in parallel_tests-1.5.1
- old
+ new
@@ -5,10 +5,14 @@
class << self
def rails_env
ENV['RAILS_ENV'] || 'test'
end
+ def purge_before_load
+ "db:test:purge" if Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0')
+ end
+
def run_in_parallel(cmd, options={})
count = " -n #{options[:count]}" unless options[:count].to_s.empty?
executable = File.expand_path("../../../bin/parallel_test", __FILE__)
command = "#{executable} --exec '#{cmd}'#{count}#{' --non-parallel' if options[:non_parallel]}"
abort unless system(command)
@@ -67,21 +71,21 @@
end
end
namespace :parallel do
desc "create test databases via db:create --> parallel:create[num_cpus]"
- task :create, :count do |t,args|
+ task :create, :count do |_,args|
ParallelTests::Tasks.run_in_parallel("rake db:create RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args)
end
desc "drop test databases via db:drop --> parallel:drop[num_cpus]"
- task :drop, :count do |t,args|
+ task :drop, :count do |_,args|
ParallelTests::Tasks.run_in_parallel("rake db:drop RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args)
end
desc "update test databases by dumping and loading --> parallel:prepare[num_cpus]"
- task(:prepare, [:count]) do |t,args|
+ task(:prepare, [:count]) do |_,args|
ParallelTests::Tasks.check_for_pending_migrations
if defined?(ActiveRecord) && ActiveRecord::Base.schema_format == :ruby
# dump then load in parallel
Rake::Task['db:schema:dump'].invoke
Rake::Task['parallel:load_schema'].invoke(args[:count])
@@ -93,33 +97,33 @@
end
end
# when dumping/resetting takes too long
desc "update test databases via db:migrate --> parallel:migrate[num_cpus]"
- task :migrate, :count do |t,args|
+ task :migrate, :count do |_,args|
ParallelTests::Tasks.run_in_parallel("rake db:migrate RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args)
end
# just load the schema (good for integration server <-> no development db)
desc "load dumped schema for test databases via db:schema:load --> parallel:load_schema[num_cpus]"
- task :load_schema, :count do |t,args|
- command = "rake db:test:purge db:schema:load RAILS_ENV=#{ParallelTests::Tasks.rails_env}"
+ task :load_schema, :count do |_,args|
+ command = "rake #{ParallelTests::Tasks.purge_before_load} db:schema:load RAILS_ENV=#{ParallelTests::Tasks.rails_env}"
ParallelTests::Tasks.run_in_parallel(ParallelTests::Tasks.suppress_output(command, "^ ->\\|^-- "), args)
end
# load the structure from the structure.sql file
desc "load structure for test databases via db:structure:load --> parallel:load_structure[num_cpus]"
- task :load_structure, :count do |t,args|
- ParallelTests::Tasks.run_in_parallel("rake db:structure:load RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args)
+ task :load_structure, :count do |_,args|
+ ParallelTests::Tasks.run_in_parallel("rake #{ParallelTests::Tasks.purge_before_load} db:structure:load RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args)
end
desc "load the seed data from db/seeds.rb via db:seed --> parallel:seed[num_cpus]"
- task :seed, :count do |t,args|
+ task :seed, :count do |_,args|
ParallelTests::Tasks.run_in_parallel("rake db:seed RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args)
end
desc "launch given rake command in parallel"
- task :rake, :command do |t, args|
+ task :rake, :command do |_, args|
ParallelTests::Tasks.run_in_parallel("RAILS_ENV=#{ParallelTests::Tasks.rails_env} rake #{args.command}")
end
['test', 'spec', 'features', 'features-spinach'].each do |type|
desc "run #{type} in parallel with parallel:#{type}[num_cpus]"