class FoodFormatter < RSpec::Core::Formatters::ProgressFormatter RSpec::Core::Formatters.register self, *%i(example_passed example_pending example_failed dump_pending dump_failures) def example_passed(_notification) @output.print(' 🥗 ') end def example_pending(_notification) @output.print(' 🍺 ') end def example_failed(_notification) @output.print(' 🥩 ') end def dump_pending(notification) return if notification.pending_examples.empty? formatted = "\n🍺 🍺 🍺 Pending 🍺 🍺 🍺\n" notification.pending_notifications.each_with_index do |pending, index| formatted << pending.fully_formatted(index + 1, ::RSpec::Core::Formatters::ConsoleCodes) end @output.puts(formatted) end def dump_failures(notification) return if notification.failure_notifications.empty? formatted = "\n🥩 🥩 🥩 Failure 🥩 🥩 🥩\n" notification.failure_notifications.each_with_index do |failure, index| formatted += failure.fully_formatted(index + 1, ::RSpec::Core::Formatters::ConsoleCodes) end @output.puts(formatted) end def dump_summary(summary) @output.puts(totals_line(summary)) end private def totals_line(summary) @output.puts("#{example_count(summary)} #{failure_count(summary)} #{pending_count(summary)}") end def example_count(summary) "#{summary.example_count} #{pluralize(summary.example_count, 'example')}" end def failure_count(summary) return if summary.failure_count.zero? formatted = '' summary.failure_count.times { formatted << '🥩 ' } formatted << pluralize(summary.failure_count, 'failure') end def pending_count(summary) return if summary.pending_count.zero? formatted = '' summary.pending_count.times { formatted << '🍺 ' } formatted << pluralize(summary.pending_count, 'pending') end def pluralize(count, string) "#{string}#{'s' unless count == 1}" end end