Module: Specjour::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/specjour/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#after_forkObject

This block is run by each worker before they begin running tests. The default action is to migrate the database, and clear it of any old data.



10
11
12
# File 'lib/specjour/configuration.rb', line 10

def after_fork
  @after_fork ||= default_after_fork
end

#after_loadObject

This block is run after the manager loads the app into memory, but before forking new worker processes. The default action is to disconnect from the ActiveRecord database.



17
18
19
# File 'lib/specjour/configuration.rb', line 17

def after_load
  @after_load ||= default_after_load
end

#before_forkObject

This block is run by the manager before forking workers. The default action is to run bundle install.



23
24
25
# File 'lib/specjour/configuration.rb', line 23

def before_fork
  @before_fork ||= default_before_fork
end

#prepareObject

This block is run on all workers when invoking ‘specjour prepare` Defaults to dropping the worker’s database and recreating it. This is especially useful when two teams are sharing workers and writing migrations at around the same time causing databases to get out of sync.



31
32
33
# File 'lib/specjour/configuration.rb', line 31

def prepare
  @prepare ||= default_prepare
end

Instance Method Details

#bundle_installObject



42
43
44
45
46
# File 'lib/specjour/configuration.rb', line 42

def bundle_install
  if system('which bundle')
    system('bundle check') || system('bundle install')
  end
end

#default_after_forkObject



54
55
56
57
58
# File 'lib/specjour/configuration.rb', line 54

def default_after_fork
  lambda do
    DbScrub.scrub if rails_with_ar?
  end
end

#default_after_loadObject



60
61
62
63
64
# File 'lib/specjour/configuration.rb', line 60

def default_after_load
  lambda do
    ActiveRecord::Base.remove_connection if rails_with_ar?
  end
end

#default_before_forkObject



48
49
50
51
52
# File 'lib/specjour/configuration.rb', line 48

def default_before_fork
  lambda do
    bundle_install
  end
end

#default_prepareObject



66
67
68
69
70
71
72
73
# File 'lib/specjour/configuration.rb', line 66

def default_prepare
  lambda do
    if rails_with_ar?
      DbScrub.drop
      DbScrub.scrub
    end
  end
end

#resetObject



35
36
37
38
39
40
# File 'lib/specjour/configuration.rb', line 35

def reset
  @before_fork = nil
  @after_fork = nil
  @after_load = nil
  @prepare = nil
end