class RspecKungFuHamster

Constants

DEAD_HAMSTER
GREEN
KUNG_FU_HAMSTER
RED
RESET
YELLOW

Public Class Methods

new(output) click to toggle source

:dump_failures

Calls superclass method
# 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

Public Instance Methods

color_positions(length) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rspec_kung_fu_hamster.rb, line 42
def display(strings)
  colorize(strings.join("\n"))
end
example_failed(notification) click to toggle source
# File lib/rspec_kung_fu_hamster.rb, line 57
def example_failed(notification)
  @example_failed += 1
  output_hamster
end
example_passed(notification) click to toggle source
# File lib/rspec_kung_fu_hamster.rb, line 49
def example_passed(notification)
  @example_passed += 1
  output_hamster
end
example_pending(notification) click to toggle source
# File lib/rspec_kung_fu_hamster.rb, line 53
def example_pending(notification)
  @example_pending += 1
  output_hamster
end
hamster_and_next() click to toggle source
# 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() click to toggle source
# File lib/rspec_kung_fu_hamster.rb, line 46
def output_hamster
  output.puts "\e[2J\e[;H" + display(hamster_and_next)
end