class Rproof::LiveReporter

Constants

INDENT
KO
OK
STATUS
WA
WARNING

Public Class Methods

new(verbose: false, cli_width: 80, justification: ([60, cli_width - 100].max)) click to toggle source
# File lib/rproof/live_reporter.rb, line 28
def initialize(verbose: false, cli_width: 80, justification: ([60, cli_width - 100].max))
  @verbose = verbose
  @justification = justification
end

Public Instance Methods

report_assertion(assertion) click to toggle source
# File lib/rproof/live_reporter.rb, line 52
def report_assertion(assertion)
  if @verbose
    if assertion.is_successful
      puts "#{INDENT}#{(assertion.comment + ' ').ljust(@justification, '_')} #{OK} obtained #{assertion.obtained.inspect}"
    else
      puts "#{INDENT}#{(assertion.comment + ' ').ljust(@justification, '_')} #{KO} expected #{assertion.expected.inspect}"
      puts "#{INDENT}#{' ' * @justification}      obtained #{assertion.obtained.inspect}"
    end
  end
end
report_campaign_begin() click to toggle source
# File lib/rproof/live_reporter.rb, line 33
def report_campaign_begin
  if @verbose
    puts "Running test campaign..."
  end
end
report_campaign_end(test_results, start_time, end_time) click to toggle source
# File lib/rproof/live_reporter.rb, line 94
def report_campaign_end(test_results, start_time, end_time)
  if test_results.is_a? Array # if false, campaign was a single test
    campaign_status = :succeed
    successes_nb = 0
    failures_nb = 0
    warnings_nb = 0
    exceptions_nb = 0

    results = test_results.flatten
    results.each do |result|
      campaign_status = TestResult.get_worse_status campaign_status, result.status
      successes_nb += result.successes_nb
      failures_nb += result.failures_nb
      warnings_nb += result.warnings.count
      exceptions_nb += result.exceptions.count
    end
    if @verbose
      puts
      puts "End of campaign: #{STATUS[campaign_status]}. #{successes_nb} successes, #{failures_nb} failures, #{warnings_nb} warnings, #{exceptions_nb} exceptions"
    else
      puts
      puts "#{STATUS[campaign_status]} in #{end_time - start_time}. #{successes_nb} successes, #{failures_nb} failures, #{warnings_nb} warnings, #{exceptions_nb} exceptions"
      if warnings_nb > 0
        puts
        puts " warnings:"
        results.each do |result|
          result.warnings.each do |warning|
            full_comment = "in #{warning.file}:#{warning.line}:#{warning.method}: #{warning.message} "
            puts "  #{full_comment.ljust(@justification, '_')} #{WA}"
          end
        end
      end
      if failures_nb > 0
        puts
        puts " failures:"
        results.each do |result|
          result.failures.each do |failure|
            full_comment = "in #{failure.file}:#{failure.line}:#{failure.method}: #{failure.comment} "
            puts "  #{full_comment.ljust(@justification, '_')} #{KO} #{"expected".bold} #{failure.expected.inspect}, #{"obtained".bold} #{failure.obtained.inspect}"
          end
        end
      end
      if exceptions_nb > 0
        print_header('exceptions')
        print_exceptions(results)
      end
    end
  end
end
report_exception(exception) click to toggle source
# File lib/rproof/live_reporter.rb, line 69
def report_exception(exception)
  if @verbose
    puts "#{INDENT}exception: " + exception.message.bold.on_magenta
    puts INDENT + exception.backtrace.join("\n#{INDENT}").bold.magenta
  end
end
report_suite_begin(id, name, description) click to toggle source
# File lib/rproof/live_reporter.rb, line 39
def report_suite_begin(id, name, description)
end
report_suite_end(id, test_results) click to toggle source
# File lib/rproof/live_reporter.rb, line 91
def report_suite_end(id, test_results)
end
report_test_begin(id, name, description) click to toggle source
# File lib/rproof/live_reporter.rb, line 42
def report_test_begin(id, name, description)
  if @verbose
    puts
    puts '-' * 120
    puts "Running #{name}"
    puts description
    puts
  end
end
report_test_end(id, test_result) click to toggle source
# File lib/rproof/live_reporter.rb, line 76
def report_test_end(id, test_result)
  if @verbose
    puts
    puts "End: #{STATUS[test_result.status]}. #{test_result.successes_nb} successes, #{test_result.failures_nb} failures, #{test_result.warnings.count} warnings, #{test_result.exceptions.count} exceptions"
  else
    case
    when !test_result.exceptions.empty? then dot = "E".bold.on_magenta
    when !test_result.failures.empty? then dot = "F".bold.red
    when !test_result.warnings.empty? then dot = "W".bold.yellow
    else dot = "."
    end
    print dot
  end
end
report_warning(warning) click to toggle source
# File lib/rproof/live_reporter.rb, line 63
def report_warning(warning)
  if @verbose
    puts "#{INDENT}#{WARNING} #{warning.message}"
  end
end

Private Instance Methods

print_exceptions(results) click to toggle source
print_header(header) click to toggle source