class RGBLED::RSpecFormatter

Attributes

path[R]

Public Class Methods

new(output) click to toggle source
# File lib/rgb_led/rspec_formatter.rb, line 21
def initialize(output)
  @output = output || StringIO.new
  @state  = :green
end
path=(value) click to toggle source
# File lib/rgb_led/rspec_formatter.rb, line 11
def path=(value)
  value = value.to_s.strip

  return nil if value.empty?
  return nil unless File.exist?(value)

  @path = value
end

Public Instance Methods

close(notification) click to toggle source
# File lib/rgb_led/rspec_formatter.rb, line 41
def close(notification)
  return if @controller.nil?

  case @state
  when :green  then @controller.green
  when :yellow then @controller.update(1, 0.1, 0)
  when :red    then @controller.red
  end
end
example_failed(notification) click to toggle source
# File lib/rgb_led/rspec_formatter.rb, line 37
def example_failed(notification)
  @state = :red
end
example_pending(notification) click to toggle source
# File lib/rgb_led/rspec_formatter.rb, line 33
def example_pending(notification)
  @state = :yellow if @state == :green
end
start(notification) click to toggle source
# File lib/rgb_led/rspec_formatter.rb, line 26
def start(notification)
  path        = RSpec.configuration.rgb_led_path
  @controller = RGBLED::Controller.open(path) unless path.nil?

  @controller.off
end