Class: RGBLED::RSpecFormatter

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

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ RSpecFormatter

Returns a new instance of RSpecFormatter.



21
22
23
24
# File 'lib/rgb_led/rspec_formatter.rb', line 21

def initialize(output)
  @output = output || StringIO.new
  @state  = :green
end

Class Attribute Details

.pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/rgb_led/rspec_formatter.rb', line 9

def path
  @path
end

Instance Method Details

#close(notification) ⇒ Object



41
42
43
44
45
46
47
48
49
# 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) ⇒ Object



37
38
39
# File 'lib/rgb_led/rspec_formatter.rb', line 37

def example_failed(notification)
  @state = :red
end

#example_pending(notification) ⇒ Object



33
34
35
# File 'lib/rgb_led/rspec_formatter.rb', line 33

def example_pending(notification)
  @state = :yellow if @state == :green
end

#start(notification) ⇒ Object



26
27
28
29
30
31
# 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