Skip to content

Instantly share code, notes, and snippets.

@smerchek
Created January 15, 2015 03:44
Show Gist options
  • Save smerchek/34ed72c4d26acf805658 to your computer and use it in GitHub Desktop.
Save smerchek/34ed72c4d26acf805658 to your computer and use it in GitHub Desktop.
Blink(1) rspec formatter
require 'rspec'
require 'blinky'
# Usage: rspec --require blink_formatter.rb --format BlinkFormatter
# fix issue where no light will cause lock-up
module Blinky
class LightFactory
class << self
alias :original_detect_lights :detect_lights
def detect_lights plugins, recipes
original_detect_lights plugins, recipes
rescue
[]
end
end
end
end
class BlinkFormatter
RSpec::Core::Formatters.register self, :start,
:dump_summary
def initialize(*args)
@light = Blinky.new.light
end
def self.turn_off!
Blinky.new.light.off!
end
def start(notification)
change_color_to :blue
end
def dump_summary(summary)
if summary.failed_examples.any?
change_color_to :red
else
change_color_to :green
end
end
private
def change_color_to(color)
case color
when :green
@light.success!
when :red
@light.failure!
when :blue
@light.building!
end
rescue
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment