Class: Turn::PrettyReporter

Inherits:
Reporter show all
Defined in:
lib/turn/reporters/pretty_reporter.rb

Overview

Pretty Reporter (by Paydro)

Example output:

TestCaseName:
     PASS test: Succesful test case.  (0:00:02:059)
    ERROR test: Bogus test case.  (0:00:02:059)
     FAIL test: Failed test case.  (0:00:02:059)

Constant Summary collapse

TAB_SIZE =

Second column left padding in chars.

10
TRACE_MARK =

Character to put in front of backtrace.

'@ '

Constants included from Colorize

Colorize::COLORLESS_TERMINALS

Instance Attribute Summary

Attributes inherited from Reporter

#io

Instance Method Summary collapse

Methods inherited from Reporter

#finish_test, #initialize

Methods included from Colorize

blue, bold, color_supported?, colorize?, #colorize?, error, fail, green, included, magenta, mark, pass, red, skip

Constructor Details

This class inherits a constructor from Turn::Reporter

Instance Method Details

#error(exception, message = nil) ⇒ Object

Invoked when a test raises an exception.



69
70
71
72
73
# File 'lib/turn/reporters/pretty_reporter.rb', line 69

def error(exception, message=nil)
  banner ERROR

  prettify(exception, message)
end

#fail(assertion, message = nil) ⇒ Object

Invoked when a test raises an assertion.



62
63
64
65
66
# File 'lib/turn/reporters/pretty_reporter.rb', line 62

def fail(assertion, message=nil)
  banner FAIL

  prettify(assertion, message)
end

#finish_case(kase) ⇒ Object

Invoked after all tests in a testcase have ben run.



83
84
85
86
# File 'lib/turn/reporters/pretty_reporter.rb', line 83

def finish_case(kase)
  # Print newline is there any tests in suite
  io.puts if kase.size > 0
end

#finish_suite(suite) ⇒ Object

After all tests are run, this is the last observable action.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/turn/reporters/pretty_reporter.rb', line 89

def finish_suite(suite)
  total      = colorize_count("%d tests", suite.count_tests, :bold)
  passes     = colorize_count("%d passed", suite.count_passes, :pass)
  assertions = colorize_count("%d assertions", suite.count_assertions, nil)
  failures   = colorize_count("%d failures", suite.count_failures, :fail)
  errors     = colorize_count("%d errors", suite.count_errors, :error)
  skips      = colorize_count("%d skips", suite.count_skips, :skip)

  io.puts "Finished in %.6f seconds." % (Time.now - @time)
  io.puts

  io.puts [ total, passes, failures, errors, skips, assertions ].join(", ")

  # Please keep this newline, since it will be useful when after test case
  # there will be other lines. For example "rake aborted!" or kind of.
  io.puts
end

#pass(message = nil) ⇒ Object

Invoked when a test passes.



50
51
52
53
54
55
56
57
58
59
# File 'lib/turn/reporters/pretty_reporter.rb', line 50

def pass(message=nil)
  banner PASS

  if message
    message = Colorize.magenta(message)
    message = message.to_s.tabto(TAB_SIZE)

    io.puts(message)
  end
end

#skip(exception, message = nil) ⇒ Object

Invoked when a test is skipped.



76
77
78
79
80
# File 'lib/turn/reporters/pretty_reporter.rb', line 76

def skip(exception, message=nil)
  banner SKIP

  prettify(exception, message)
end

#start_case(kase) ⇒ Object

Invoked before a testcase is run.



37
38
39
40
41
# File 'lib/turn/reporters/pretty_reporter.rb', line 37

def start_case(kase)
  # Print case name if there any tests in suite
  # TODO: Add option which will show all test cases, even without tests?
  io.puts kase.name if kase.size > 0
end

#start_suite(suite) ⇒ Object

At the very start, before any testcases are run, this is called.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/turn/reporters/pretty_reporter.rb', line 22

def start_suite(suite)
  @suite  = suite
  @time   = Time.now

  io.puts Colorize.bold("Loaded Suite #{suite.name}")
  io.puts
  if suite.seed
    io.puts "Started at #{Time.now} w/ seed #{suite.seed}."
  else
    io.puts "Started at #{Time.now}."
  end
  io.puts
end

#start_test(test) ⇒ Object

Invoked before a test is run.



44
45
46
47
# File 'lib/turn/reporters/pretty_reporter.rb', line 44

def start_test(test)
  @test_time = Time.now
  @test = test
end