class Utils::LineFormatter

def close(_ignore)

Parameters:
  • _ignore (Object) -- ignored parameter, present for interface
def close(_ignore)
  @errors_lst.close
end

def description(example, full: ENV['VERBOSE'].to_i == 1)

Returns:
  • (String) - the appropriate description based on the full parameter value

Parameters:
  • full (TrueClass, FalseClass) -- determines whether to return the
  • example (Object) -- the example object containing description
def description(example, full: ENV['VERBOSE'].to_i == 1)
  if full
    example.example.full_description
  else
    example.example.description
  end
end

def dump_failure(example)

Parameters:
  • example (Object) -- the test example that failed
def dump_failure(example)
  output.puts(
    description(example, full: true),
    dump_failure_for_example(example)
  )
end

def dump_failure_for_example(example)

Returns:
  • (String) - a formatted string containing the failure details including

Parameters:
  • example (Object) -- the test example object containing execution results
def dump_failure_for_example(example)
  result = ''
  exception = execution_result(example).exception
  exception_class_name = exception.class.name
  result << "Failure/Error: #{read_failed_line(example)}\n"
  result << "#{exception_class_name}:\n" unless exception_class_name =~ /RSpec/
  if m = exception.message
    m.to_s.split("\n").each { |line| result << "  #{line}\n" }
  end
  result
end

def dump_failure_to_error_file(example)

Parameters:
  • example (Object) -- the test example that failed
def dump_failure_to_error_file(example)
  @errors_lst.flock File::LOCK_EX
  @errors_lst.puts "%s\n%3.3fs %s\n%s\n%s" % [
    location(example), run_time(example), description(example, full: true),
    dump_failure_for_example(example), format_backtrace(example, folding: true)
  ]
ensure
  @errors_lst.flock File::LOCK_UN
end

def dump_summary(summary)

Parameters:
  • summary (Object) -- the summary object to be processed and displayed
def dump_summary(summary)
  line = summary_line(summary)
  @errors_lst.puts ?= * 80, line
  output.puts ?= * Tins::Terminal.columns, line
end

def example_failed(example)

Parameters:
  • example (Object) -- the test example that failed
def example_failed(example)
  dump_failure_to_error_file(example)
  output.puts format_line(example)
  dump_failure(example)
end

def example_passed(example)

Parameters:
  • example (Object) -- the test example that has passed
def example_passed(example)
  output.puts format_line(example)
end

def example_pending(example)

Parameters:
  • example (Object) -- the test example that is pending
def example_pending(example)
  output.puts format_line(example)
end

def execution_result(example)

Returns:
  • (Object) - the execution result metadata stored in the example's metadata hash

Parameters:
  • example (Object) -- the example object containing test metadata
def execution_result(example)
  example.example.metadata[:execution_result]
end

def failure_color(text)

Returns:
  • (String) - the colorized text wrapped with red formatting codes

Parameters:
  • text (String) -- the text to be colorized in red
def failure_color(text)
  Term::ANSIColor.red(text)
end

def format_backtrace(example, folding: false, limit: nil)

Returns:
  • (String) - the formatted backtrace as a string with lines separated by newlines

Parameters:
  • limit (Integer, nil) -- the maximum number of backtrace lines to include
  • folding (TrueClass, FalseClass) -- whether to wrap the backtrace with folding markers
  • example (Object) -- the example object containing the exception with backtrace
def format_backtrace(example, folding: false, limit: nil)
  backtrace = execution_result(example).exception.backtrace
  backtrace.nil? and return ''
  if limit
    backtrace = backtrace[0, limit]
  end
  result = []
  folding and result << '{{{'
  for line in backtrace
    result << RSpec::Core::Metadata::relative_path(line)
  end
  folding and result << '}}}'
  result * ?\n
end

def format_line(example)

Returns:
  • (String) - the formatted and colorized test result string

Parameters:
  • example (Object) -- the test example to format
def format_line(example)
  args = [ location(example), run_time(example), description(example) ]
  uncolored = "%s # S %3.3fs %s" % args
  uncolored = uncolored[0, Tins::Terminal.columns]
  case execution_result(example).status
  when :passed
    success_color(uncolored)
  when :failed
    failure_color(uncolored)
  when :pending
    pending_color(uncolored)
  else
    uncolored % args
  end
end

def initialize(output)

Parameters:
  • output (IO) -- the output stream to be used for logging errors
def initialize(output)
  @output = output
  @output.sync = true
  filename = 'errors.lst'
  @errors_lst = File.new(filename, 'w')
  @errors_lst.sync = true
end

def location(example)

Returns:
  • (String) - the relative file path and line number for the example

Parameters:
  • example (Object) -- the RSpec example object containing metadata
def location(example)
  location = example.example.metadata[:location]
  unless location.include?(?/)
    location = example.example.metadata[:example_group][:location]
  end
  RSpec::Core::Metadata::relative_path(location)
end

def pending_color(text)

Returns:
  • (String) - the colorized text with yellow formatting applied

Parameters:
  • text (String) -- the text to be colorized
def pending_color(text)
  Term::ANSIColor.yellow(text)
end

def read_failed_line(example)

Returns:
  • (String) - an empty string with whitespace stripped

Parameters:
  • example (Object) -- the test example object
def read_failed_line(example)
  ''.strip
end

def run_time(example)

Returns:
  • (Float, nil) - the execution time of the example or nil if not available

Parameters:
  • example (Object) -- the test example object to get run time for
def run_time(example)
  execution_result(example).run_time
end

def start(_ignore)

Parameters:
  • _ignore (Object) -- this parameter is ignored and exists for
def start(_ignore)
  output.puts "Storing error list in #{@errors_lst.path.inspect}: "
  output.puts ?- * Tins::Terminal.columns
end

def success_color(text)

Returns:
  • (String) - the input text wrapped with green color ANSI escape codes

Parameters:
  • text (String) -- the text to be formatted with green color
def success_color(text)
  Term::ANSIColor.green(text)
end

def summary_line(summary)

Returns:
  • (String) - a formatted summary string with test statistics and

Parameters:
  • summary (Object) -- an object containing test execution statistics
def summary_line(summary)
  failure_percentage = 100 * summary.failure_count.to_f / summary.example_count
  failure_percentage.nan? and failure_percentage = 0.0
  pending_percentage = 100 * summary.pending_count.to_f / summary.example_count
  pending_percentage.nan? and pending_percentage = 0.0
  "%u of %u (%.2f %%) failed, %u pending (%.2f %%) in %.3f seconds" % [
    summary.failure_count,
    summary.example_count,
    failure_percentage,
    summary.pending_count,
    pending_percentage,
    summary.duration,
  ]
end