Class: RspecKungFuHamster
- Inherits:
-
RSpec::Core::Formatters::BaseTextFormatter
- Object
- RSpec::Core::Formatters::BaseTextFormatter
- RspecKungFuHamster
- Defined in:
- lib/rspec_kung_fu_hamster.rb
Constant Summary collapse
- GREEN =
"\e[32m"
- YELLOW =
"\e[33m"
- RED =
"\e[31m"
- RESET =
"\e[0m"
- KUNG_FU_HAMSTER =
[ [ " ()__() ", " / o o\\ | ", " |' =Y=';-| ", " { \\ / } ", " mmm mmm " ],[ " ()__() ", " / o o\\ ; ", " |' =Y=';-/ ", " { \\ / } ", " mmm mmm " ],[ " ()__() ", " / o o\\ ", " |' =Y=';----", " { \\ / } ", " mmm mmm " ],[ " ()__() ", " / o o\\ ", " |' =Y=';-\\ ", " { \\ / } \\ ", " mmm mmm " ],[ " ()__() ", " / o o\\ ", " |' =Y=';----", " { \\ / } ", " mmm mmm " ],[ " ()__() ", " / o o\\ \\ ", " |' =Y=';-\\ ", " { \\ / } ", " mmm mmm " ]]
- DEAD_HAMSTER =
[ " ()__() ", " / X X\\ | ", " |' =Y=';-| ", " { \\ / } ", " mmm mmm " ]
Instance Method Summary collapse
- #color_positions(length) ⇒ Object
- #colorize(string) ⇒ Object
- #display(strings) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_passed(notification) ⇒ Object
- #example_pending(notification) ⇒ Object
- #hamster_and_next ⇒ Object
-
#initialize(output) ⇒ RspecKungFuHamster
constructor
:dump_failures.
- #output_hamster ⇒ Object
Constructor Details
#initialize(output) ⇒ RspecKungFuHamster
:dump_failures
16 17 18 19 20 21 22 |
# File 'lib/rspec_kung_fu_hamster.rb', line 16 def initialize(output) @index = 0 @example_passed = 0 @example_pending = 0 @example_failed = 0 super(output) end |
Instance Method Details
#color_positions(length) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rspec_kung_fu_hamster.rb', line 24 def color_positions(length) total = @example_passed + @example_pending + @example_failed passed_percent = @example_passed * length / total pending_percent = @example_pending * length / total [passed_percent, passed_percent + pending_percent, length] end |
#colorize(string) ⇒ Object
37 38 39 40 |
# File 'lib/rspec_kung_fu_hamster.rb', line 37 def colorize(string) green, yellow, red = color_positions(string.length) GREEN + string[0...green] + YELLOW + string[green...yellow] + RED + string[yellow...red] + RESET end |
#display(strings) ⇒ Object
42 43 44 |
# File 'lib/rspec_kung_fu_hamster.rb', line 42 def display(strings) colorize(strings.join("\n")) end |
#example_failed(notification) ⇒ Object
57 58 59 60 |
# File 'lib/rspec_kung_fu_hamster.rb', line 57 def example_failed(notification) @example_failed += 1 output_hamster end |
#example_passed(notification) ⇒ Object
49 50 51 52 |
# File 'lib/rspec_kung_fu_hamster.rb', line 49 def example_passed(notification) @example_passed += 1 output_hamster end |
#example_pending(notification) ⇒ Object
53 54 55 56 |
# File 'lib/rspec_kung_fu_hamster.rb', line 53 def example_pending(notification) @example_pending += 1 output_hamster end |
#hamster_and_next ⇒ Object
62 63 64 |
# File 'lib/rspec_kung_fu_hamster.rb', line 62 def hamster_and_next KUNG_FU_HAMSTER[@index % KUNG_FU_HAMSTER.length].tap { @index += 1 } end |
#output_hamster ⇒ Object
46 47 48 |
# File 'lib/rspec_kung_fu_hamster.rb', line 46 def output_hamster output.puts "\e[2J\e[;H" + display(hamster_and_next) end |