class Spectator::Runner

Attributes

config[R]
path_watcher[R]
spec_runner[R]
specs_matcher[R]
success_notifier[R]
ui[R]

Public Class Methods

new(config) click to toggle source
# File lib/spectator.rb, line 40
def initialize(config)
  @config            = config
  @path_watcher      = PathWatcher.new(config)
  @ui                = UI.new(config)
  @spec_runner       = SpecRunner.new(config)
  @success_notifier  = SuccessNotifier.new(config)
  @specs_matcher     = SpecsMatcher.new(config)
end

Public Instance Methods

interrupt_handler() click to toggle source
# File lib/spectator.rb, line 85
def interrupt_handler
  puts ' (Interrupted with CTRL+C)'.red
  p [ui.status, ui.interrupted_status]
  case ui.interrupted_status
  when :wait_for_input then ui.exit
  when :running_specs  then ui.wait_for_changes
  when :exiting        then Kernel.abort
  else Thread.new { ui.ask_what_to_do }
  end
end
run() click to toggle source
# File lib/spectator.rb, line 51
def run
  $spectator_debug = config.debug

  path_watcher.on_change { ui << :run_specs }
  path_watcher.watch_paths!

  ui.on(:run_all)   { run_all_handler }
  ui.on(:run_specs) { run_specs_handler }
  ui.on(:interrupt) { interrupt_handler }

  trap('INT') { ui.interrupt! }
  ui.start
end
run_all_handler() click to toggle source
# File lib/spectator.rb, line 65
def run_all_handler
  return unless ui.can_run_specs?
  ui.status = :running_specs
  result = ui.run(spec_runner.command)
  success_notifier.notify(result)
  ui.wait_for_changes
end
run_specs_handler() click to toggle source
# File lib/spectator.rb, line 73
def run_specs_handler
  return unless ui.can_run_specs?
  ui.status = :running_specs
  files = path_watcher.pop_files
  specs = specs_matcher.specs_for(files)
  if specs.any?
    result = ui.run spec_runner.command(specs)
    success_notifier.notify(result)
  end
  ui.wait_for_changes
end