Guest User

Untitled

a guest
Jan 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
  2. RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed
  3.  
  4. def initialize(*args)
  5. super(*args)
  6. @index = 0
  7. end
  8.  
  9. def increase_index!
  10. @index += 1
  11. end
  12.  
  13. def error_word
  14. "ERROU"
  15. end
  16.  
  17. def error_char
  18. error_word[current_error_word_index]
  19. end
  20.  
  21. def current_error_word_index
  22. max_index = error_word.length - 1
  23. adjusted_index = [max_index, @index].min
  24. end
  25.  
  26. def example_passed(_notification)
  27. output_print('.', :success)
  28. end
  29.  
  30. def example_pending(_notification)
  31. output_print('*', :pending)
  32. end
  33.  
  34.  
  35. def example_failed(_notification)
  36. letter = error_char
  37. output_print(letter, :failure)
  38. increase_index!
  39. end
  40.  
  41. def output_print(character, console_code)
  42. output.print RSpec::Core::Formatters::ConsoleCodes.wrap(character, console_code)
  43. end
  44. end
Add Comment
Please, Sign In to add comment