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

#rspec_formatterObject



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

def rspec_formatter
  @rspec_formatter ||= default_rspec_formatter
end

#rsync_optionsObject



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

def rsync_options
  @rsync_options ||= default_rsync_options
end

Instance Method Details

#bundle_installObject



52
53
54
55
56
# File 'lib/specjour/configuration.rb', line 52

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

#default_after_forkObject



64
65
66
67
68
# File 'lib/specjour/configuration.rb', line 64

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

#default_after_loadObject



70
71
72
73
74
# File 'lib/specjour/configuration.rb', line 70

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

#default_before_forkObject



58
59
60
61
62
# File 'lib/specjour/configuration.rb', line 58

def default_before_fork
  lambda do
    bundle_install
  end
end

#default_prepareObject



76
77
78
79
80
81
82
83
# File 'lib/specjour/configuration.rb', line 76

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

#default_rspec_formatterObject



85
86
87
88
89
# File 'lib/specjour/configuration.rb', line 85

def default_rspec_formatter
  lambda do
    ::RSpec::Core::Formatters::ProgressFormatter
  end
end

#default_rsync_optionsObject



91
92
93
# File 'lib/specjour/configuration.rb', line 91

def default_rsync_options
  "-aL --delete --ignore-errors"
end

#resetObject



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

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