Class: RSpecTurbo::DbSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_turbo/db_setup.rb

Overview

Ensures N test databases exist, one per worker slot, by spawning a Rails db setup process per slot (each with its own TEST_ENV_NUMBER).

The result is cached by a fingerprint of db/schema.rb + db/seeds.rb plus the worker count, so repeat runs skip setup entirely. Set RSPEC_TURBO_FORCE_SETUP=1 to force recreation.

Constant Summary collapse

FINGERPRINT_FILES =
["db/schema.rb", "db/seeds.rb"].freeze
SETUP_COMMAND =
["bundle", "exec", "rails", "db:drop", "db:create", "db:schema:load", "db:seed"].freeze

Instance Method Summary collapse

Constructor Details

#initialize(num_workers, force: Config.force_setup?) ⇒ DbSetup

Returns a new instance of DbSetup.



17
18
19
20
# File 'lib/rspec_turbo/db_setup.rb', line 17

def initialize(num_workers, force: Config.force_setup?)
  @n = num_workers
  @force = force
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


34
# File 'lib/rspec_turbo/db_setup.rb', line 34

def cached? = File.exist?(marker_path)

#run!Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec_turbo/db_setup.rb', line 22

def run!
  return true if !@force && cached?

  FileUtils.mkdir_p(Config.log_dir)
  failed = wait_all(spawn_all)

  return write_marker && true if failed.empty?

  failed.each { |worker| show_log(worker) }
  false
end