Class: Riot::DotMatrixReporter

Inherits:
IOReporter show all
Defined in:
lib/riot/reporter/dot_matrix.rb

Overview

Outputs in the dot-notion almost everyone should be familiar with, “.” implies pass, “F” implies a failure, and “E” implies an error. If ansi-coloring is available, it is used. Error and failure messages are buffered for output until the end.

Direct Known Subclasses

PrettyDotMatrixReporter

Instance Attribute Summary

Attributes inherited from Reporter

#current_context, #errors, #failures, #passes

Instance Method Summary collapse

Methods inherited from IOReporter

#filter_backtrace, #format_error, #green, #line_info, #plain?, #print, #puts, #red, #with_color, #yellow

Methods inherited from Reporter

#describe_context, #new, #report, #success?, #summarize

Constructor Details

#initialize(*args) ⇒ DotMatrixReporter

Creates a new DotMatrixReporter and initializes the failure/error details buffer.

Parameters:

  • writer (IO)

    the writer to use for results

  • options (Hash)

    options for reporter



9
10
11
12
# File 'lib/riot/reporter/dot_matrix.rb', line 9

def initialize(*args)
  super
  @details = []
end

Instance Method Details

#error(description, e) ⇒ Object

Prints a “E” and saves the error details (including backtrace) for the end. Prints in red if possible.

Parameters:

  • description (String)

    the description of the assertion

  • ] (Array<Symbol, Exception])

    result the exception from the assertion



33
34
35
36
# File 'lib/riot/reporter/dot_matrix.rb', line 33

def error(description, e)
  print red("E")
  @details << "ERROR - #{test_detail(description, format_error(e))}"
end

#fail(description, message, line, file) ⇒ Object

Prints a “F” and saves the failure details (including line number and file) for the end. Prints in yellow if possible.

Parameters:

  • description (String)

    the description of the assertion

  • ] (Array<Symbol, String, Number, String])

    response the evaluation response from the assertion



25
26
27
28
# File 'lib/riot/reporter/dot_matrix.rb', line 25

def fail(description, message, line, file)
  print yellow("F")
  @details << "FAILURE - #{test_detail(description, message)} #{line_info(line, file)}".strip
end

#pass(description, message) ⇒ Object

Prints a “.”. Prints in green if possible.

Parameters:

  • description (String)

    the description of the assertion

  • ] (Array<Symbol, String])

    result the evaluation response from the assertion



17
18
19
# File 'lib/riot/reporter/dot_matrix.rb', line 17

def pass(description, message)
  print green(".")
end

#results(time_taken) ⇒ Object

Called after all contexts have finished. This is where the final results can be output.

Parameters:

  • time_taken (Number)

    number of seconds taken to run everything



39
40
41
42
# File 'lib/riot/reporter/dot_matrix.rb', line 39

def results(time_taken)
  puts "\n#{@details.join("\n\n")}" unless @details.empty?
  super
end