Class: FruityFormatter

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/fruity_formatter.rb

Constant Summary collapse

FRUITS =
{
  strawberry: { char: "🍓", color: :red },
  cherry: { char: "🍒", color: :magenta },
  pear: { char: "🍐", color: :green },
  peach: { char: "🍑", color: :yellow },
  tomato: { char: "🍅", color: :red },
  eggplant: { char: "🍆", color: :magenta },
  tangerine: { char: "🍊", color: :yellow },
  grape: { char: "🍇", color: :magenta },
  melon: { char: "🍈", color: :green },
  lemon: { char: "🍋", color: :yellow },
  watermelon: { char: "🍉", color: :red },
  banana: { char: "🍌", color: :yellow },
  apple: { char: "🍎", color: :red },
  pineapple: {char:  "🍍 ", color: :yellow}
}
FRUIT_NAMES =
[
  :strawberry,
  :cherry,
  :pear,
  :peach,
  :tomato,
  :eggplant,
  :grape,
  :melon,
  :watermelon,
  :tangerine,
  :lemon,
  :banana,
  :apple,
  :pineapple
]

Instance Method Summary collapse

Instance Method Details

#example_failed(example) ⇒ Object



57
58
59
60
# File 'lib/fruity_formatter.rb', line 57

def example_failed(example)
  super(example)
  output.print failure_emoji
end

#example_passed(example) ⇒ Object



53
54
55
56
# File 'lib/fruity_formatter.rb', line 53

def example_passed(example)
  super(example)
  output.print grab_a_fruit
end

#failure_emojiObject



46
47
48
# File 'lib/fruity_formatter.rb', line 46

def failure_emoji
  color("🍄", :black)
end

#grab_a_fruitObject



37
38
39
40
41
42
43
44
45
# File 'lib/fruity_formatter.rb', line 37

def grab_a_fruit
  fruit_name = FRUIT_NAMES[@cur_fruit]
  @cur_fruit += 1
  if @cur_fruit > FRUIT_NAMES.size-1
    @cur_fruit = 0
  end
  fruit = FRUITS[fruit_name]
  color(fruit[:char], fruit[:color])
end

#start(example_count) ⇒ Object



49
50
51
52
# File 'lib/fruity_formatter.rb', line 49

def start(example_count)
  @cur_fruit = 0
  super(example_count)
end