Class: Autospec::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/autospec/manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Manager

Returns a new instance of Manager.



18
19
20
21
22
23
24
25
26
# File 'lib/autospec/manager.rb', line 18

def initialize(opts = {})
  @opts = opts
  @debug = opts[:debug]
  @auto_run_all = ENV["AUTO_RUN_ALL"] != "0"
  @queue = []
  @mutex = Mutex.new
  @signal = ConditionVariable.new
  @runners = [ruby_runner]
end

Class Method Details

.run(opts = {}) ⇒ Object



14
15
16
# File 'lib/autospec/manager.rb', line 14

def self.run(opts = {})
  self.new(opts).run
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/autospec/manager.rb', line 28

def run
  Signal.trap("HUP") do
    stop_runners
    exit
  end

  Signal.trap("INT") do
    begin
      stop_runners
    rescue => e
      puts "FAILED TO STOP RUNNERS #{e}"
    end
    exit
  end

  ensure_all_specs_will_run if @auto_run_all
  start_runners
  start_service_queue
  listen_for_changes

  puts "Press [ENTER] to stop the current run"
  puts "Press [ENTER] while stopped to run all specs" unless @auto_run_all
  while @runners.any?(&:running?)
    STDIN.gets
    process_queue
  end
rescue => e
  fail(e, "failed in run")
ensure
  stop_runners
end