Module: TestConsole::Output

Includes:
Colors, Config
Included in:
TestConsole
Defined in:
lib/test_console/output.rb

Constant Summary

Constants included from Colors

Colors::COLORS

Instance Method Summary collapse

Methods included from Colors

#color, #reset_color, #start_color

Instance Method Details

#error(message, backtrace = nil) ⇒ Object

Puts out an error. The error is written to STDERR and colored in the error color.



37
38
39
40
# File 'lib/test_console/output.rb', line 37

def error(message, backtrace=nil)
  STDERR.puts color(message, error_color)
  backtrace.each {|line| line_color = (line[0..1] == '/') ? backtrace_local_color : backtrace_gem_color; STDERR.puts color(line, line_color)} unless backtrace.nil? || backtrace.empty?
end

#out(text, text_color = nil, *opts) ⇒ Object

Writes content out to the terminal Use Hirb to format tables. Can specify a color using one of the defined color constants

Examples

out 'some_text', :blue  # Prints out the text in blue


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/test_console/output.rb', line 20

def out(text, text_color=nil, *opts)
  extend Hirb::Console
  text = text.to_a if text.kind_of? ActiveRecord::Base

  if text.kind_of? Array
    STDOUT.puts start_color text_color if text_color
    table text, *opts
    STDOUT.puts reset_color if text_color
  else
    text = color(text, text_color) if text_color

    STDOUT.puts text
  end
end


42
43
44
45
46
47
48
# File 'lib/test_console/output.rb', line 42

def print_negatives(items, color)
  if items.kind_of? Array
    items.each do |item|
      out "\n#{item.long_display}", color
    end
  end
end

Outputs a summary of the results



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/test_console/output.rb', line 51

def print_result_summary(result, time_taken=0)
  if result.failure_count == 0 && result.error_count == 0
    final_color = success_color
  elsif result.error_count > 0
    final_color = error_color
  else
    final_color = fail_color
  end

  out "\nTests: #{result.run_count}, Assertions: #{result.assertion_count}, Fails:  #{result.failure_count}, Errors: #{result.error_count}, Time taken #{sprintf('%.2f', time_taken)}s", final_color
end