Skip to content

Instantly share code, notes, and snippets.

@lucaschain
Last active August 20, 2018 15:13
Show Gist options
  • Save lucaschain/03de76cf25ca928076a31e864d0492e6 to your computer and use it in GitHub Desktop.
Save lucaschain/03de76cf25ca928076a31e864d0492e6 to your computer and use it in GitHub Desktop.
Fausto Silva's "errou" formatter
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
@lucaschain
Copy link
Author

usage:

rspec --require ./errou_formatter.rb --format CustomFormatter

@oborba
Copy link

oborba commented Jan 9, 2018

❤️ ❤️ ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment