Last active
August 20, 2018 15:13
-
-
Save lucaschain/03de76cf25ca928076a31e864d0492e6 to your computer and use it in GitHub Desktop.
Fausto Silva's "errou" formatter
This file contains hidden or 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
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter | |
RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed | |
def initialize(*args) | |
super(*args) | |
@index = 0 | |
end | |
def increase_index! | |
@index += 1 | |
end | |
def error_word | |
"ERROU" | |
end | |
def error_char | |
error_word[current_error_word_index] | |
end | |
def current_error_word_index | |
max_index = error_word.length - 1 | |
adjusted_index = [max_index, @index].min | |
end | |
def example_passed(_notification) | |
output_print('.', :success) | |
end | |
def example_pending(_notification) | |
output_print('*', :pending) | |
end | |
def example_failed(_notification) | |
letter = error_char | |
output_print(letter, :failure) | |
increase_index! | |
end | |
def output_print(character, console_code) | |
output.print RSpec::Core::Formatters::ConsoleCodes.wrap(character, console_code) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: