class Foodtaster::RSpecRun

Attributes

client[R]

Public Class Methods

current() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 40
def current
  @instance ||= self.new
end
new() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 5
def initialize
  @client = nil
  @server_process = nil
  @stopped = false
end

Public Instance Methods

start() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 11
def start
  setup_signal_handlers
  start_server_and_connect_client

  if @client && @server_process && !@server_process.alive?
    Foodtaster.logger.fatal "Failed to start Foodtaster DRb Server:\n\n#{@server_process.output}"
    exit 1
  elsif !@client || !@server_process
    Foodtaster.logger.fatal "Failed to connect to Foodtaster DRb Server"
    exit 1
  end
end
stop() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 24
def stop
  return if @stopped

  @stopped = true
  puts "" # newline after rspec output
  Vm.shutdown_running_vms if Foodtaster.config.shutdown_vms
  terminate_server
end

Private Instance Methods

connect_client(drb_port) click to toggle source
# File lib/foodtaster/rspec_run.rb, line 76
def connect_client(drb_port)
  Foodtaster::Client.connect(drb_port, @server_process)
end
setup_signal_handlers() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 47
def setup_signal_handlers
  terminator = proc {
    self.stop
    exit 1
  }

  trap("INT", &terminator)
  trap("TERM", &terminator)

  at_exit do
    self.stop
  end
end
start_server(drb_port) click to toggle source
# File lib/foodtaster/rspec_run.rb, line 68
def start_server(drb_port)
  Foodtaster::ServerProcess.new(drb_port)
end
start_server_and_connect_client() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 61
def start_server_and_connect_client
  drb_port = Foodtaster.config.drb_port

  @server_process = start_server(drb_port) if Foodtaster.config.start_server
  @client = connect_client(drb_port)
end
terminate_server() click to toggle source
# File lib/foodtaster/rspec_run.rb, line 72
def terminate_server
  @server_process && @server_process.terminate
end