Sha256: 7d5a73cc29453e2509087e41d349c03d1cfaaa942fca2d541e3e6fd8d5c68dea

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

require "rspec/parallel"

namespace :db do
  namespace :test do
    desc "Prepare sequence of databases for parallel-rspec"
    task :prepare_sequential, ["concurrency"] => :environment do |_, args|
      require "active_record/tasks/database_tasks"
      concurrency = Integer(args[:concurrency] || RSpec::Parallel.configuration.concurrency)

      concurrency.times do |i|
        database = ActiveRecord::Base.configurations["test"]["database"] + i.to_s
        configuration = ActiveRecord::Base.configurations["test"].merge("database" => database)

        ActiveRecord::Tasks::DatabaseTasks.drop(configuration) unless ENV["CI"]
        puts "Create and load schema to #{database}"
        ActiveRecord::Tasks::DatabaseTasks.create(configuration)
        stdout = $stdout
        begin
          $stdout = File.open(File::NULL, "w")
          ActiveRecord::Tasks::DatabaseTasks.load_schema_for(configuration)
        ensure
          $stdout = stdout
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parallel-rspec-0.1.1 lib/rspec/parallel/rake_task.rb
parallel-rspec-0.1.0 lib/rspec/parallel/rake_task.rb