Class: Spectator::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Runner

Returns a new instance of Runner.



40
41
42
43
44
45
46
47
# 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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



49
50
51
# File 'lib/spectator.rb', line 49

def config
  @config
end

#path_watcherObject (readonly)

Returns the value of attribute path_watcher.



49
50
51
# File 'lib/spectator.rb', line 49

def path_watcher
  @path_watcher
end

#spec_runnerObject (readonly)

Returns the value of attribute spec_runner.



49
50
51
# File 'lib/spectator.rb', line 49

def spec_runner
  @spec_runner
end

#specs_matcherObject (readonly)

Returns the value of attribute specs_matcher.



49
50
51
# File 'lib/spectator.rb', line 49

def specs_matcher
  @specs_matcher
end

#success_notifierObject (readonly)

Returns the value of attribute success_notifier.



49
50
51
# File 'lib/spectator.rb', line 49

def success_notifier
  @success_notifier
end

#uiObject (readonly)

Returns the value of attribute ui.



49
50
51
# File 'lib/spectator.rb', line 49

def ui
  @ui
end

Instance Method Details

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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_specs) do
    next 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

  ui.on(:interrupt) do
    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

  trap('INT') { ui.interrupt! }

  ui.on(:run_all) do
    next unless ui.can_run_specs?

    ui.status = :running_specs
    result = ui.run(spec_runner.command)
    success_notifier.notify(result)
    ui.status = nil if ui.status == :running_specs
  end

  ui.start
end