class Attestify::ColorReporter

Reports results to the console, with color!

Private Instance Methods

color_code(color) click to toggle source
# File lib/attestify/color_reporter.rb, line 85
def color_code(color) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
  case color
  when :reset
    "\e[0m"
  when :bold_red
    "\e[1;31m"
  when :red
    "\e[31m"
  when :yellow
    "\e[33m"
  when :green
    "\e[32m"
  when :cyan
    "\e[36m"
  end
end
color_for(result) click to toggle source
# File lib/attestify/color_reporter.rb, line 102
def color_for(result) # rubocop:disable Metrics/MethodLength
  if result.skipped?
    :yellow
  elsif result.passed?
    :green
  elsif result.errored?
    :bold_red
  elsif result.failed?
    :red
  else
    :none
  end
end
color_for_detail(failure_detail) click to toggle source
# File lib/attestify/color_reporter.rb, line 116
def color_for_detail(failure_detail)
  case failure_detail.type
  when :error
    :bold_red
  when :failure
    :red
  else
    :none
  end
end
colorize(text, color) click to toggle source
# File lib/attestify/color_reporter.rb, line 81
def colorize(text, color)
  "#{color_code(color)}#{text}#{color_code(:reset)}"
end
colorize_from_totals(text) click to toggle source
# File lib/attestify/color_reporter.rb, line 58
def colorize_from_totals(text) # rubocop:disable Metrics/MethodLength
  color =
    if @total_errors > 0
      :bold_red
    elsif @total_failures > 0
      :red
    elsif @total_skips > 0
      :yellow
    else
      :green
    end

  colorize(text, color)
end
colorize_if_positive(text, amount, color) click to toggle source
# File lib/attestify/color_reporter.rb, line 73
def colorize_if_positive(text, amount, color)
  if amount > 0
    colorize(text, color)
  else
    text
  end
end
comment(message) click to toggle source
Calls superclass method Attestify::Reporter#comment
# File lib/attestify/color_reporter.rb, line 54
def comment(message)
  colorize(super, :cyan)
end
print_result_code(result) click to toggle source
Calls superclass method Attestify::Reporter#print_result_code
puts_failure_detail(failure_detail, number, sub_number) click to toggle source
Calls superclass method Attestify::Reporter#puts_failure_detail
# File lib/attestify/color_reporter.rb, line 14
def puts_failure_detail(failure_detail, number, sub_number)
  print color_code(color_for_detail(failure_detail))
  super
  print color_code(:reset)
end
puts_failure_header(result, number) click to toggle source
Calls superclass method Attestify::Reporter#puts_failure_header
# File lib/attestify/color_reporter.rb, line 8
def puts_failure_header(result, number)
  print color_code(color_for(result))
  super
  print color_code(:reset)
end
rerun_test_command(result) click to toggle source
Calls superclass method Attestify::Reporter#rerun_test_command
# File lib/attestify/color_reporter.rb, line 50
def rerun_test_command(result)
  colorize(super, color_for(result))
end
total_assertions() click to toggle source
Calls superclass method Attestify::Reporter#total_assertions
# File lib/attestify/color_reporter.rb, line 42
def total_assertions
  colorize_from_totals(super)
end
total_errors() click to toggle source
Calls superclass method Attestify::Reporter#total_errors
# File lib/attestify/color_reporter.rb, line 34
def total_errors
  colorize_if_positive(super, @total_errors, :bold_red)
end
total_failed_assertions() click to toggle source
# File lib/attestify/color_reporter.rb, line 46
def total_failed_assertions
  colorize_if_positive(super, @total_failed_assertions, :red)
end
total_failures() click to toggle source
Calls superclass method Attestify::Reporter#total_failures
# File lib/attestify/color_reporter.rb, line 30
def total_failures
  colorize_if_positive(super, @total_failures, :red)
end
total_skips() click to toggle source
Calls superclass method Attestify::Reporter#total_skips
# File lib/attestify/color_reporter.rb, line 38
def total_skips
  colorize_if_positive(super, @total_skips, :yellow)
end
total_tests() click to toggle source
Calls superclass method Attestify::Reporter#total_tests
# File lib/attestify/color_reporter.rb, line 26
def total_tests
  colorize_from_totals(super)
end