Created
January 15, 2015 03:44
-
-
Save smerchek/34ed72c4d26acf805658 to your computer and use it in GitHub Desktop.
Blink(1) rspec formatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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