Class: Turn::CueReporter

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

Overview

Cue Reporter

Inspired by Shindo.

Constant Summary

Constants included from Colorize

Turn::Colorize::COLORLESS_TERMINALS

Instance Attribute Summary

Attributes inherited from Reporter

#io

Instance Method Summary collapse

Methods inherited from Reporter

#finish_case, #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



62
63
64
65
66
67
68
69
# File 'lib/turn/reporters/cue_reporter.rb', line 62

def error(exception, message=nil)
  #message = exception.to_s.split("\n")[2..-1].join("\n")
  message = message || exception.to_s
  io.puts("#{ERROR}")
  io.puts(message) #if message

  prompt
end

#fail(assertion, message = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/turn/reporters/cue_reporter.rb', line 47

def fail(assertion, message=nil)
  io.puts(" #{FAIL}")
  #message = assertion.location[0] + "\n" + assertion.message #.gsub("\n","\n")
  message = message || assertion.to_s
  #if message
    message = Colorize.red(message)
    message = message.to_s.tabto(8)
    io.puts(message)
  #end

  show_captured_output

  prompt
end

#finish_suite(suite) ⇒ Object

def finish_case(kase) end



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/turn/reporters/cue_reporter.rb', line 111

def finish_suite(suite)
  total      = suite.count_tests
  passes     = suite.count_passes
  assertions = suite.count_assertions
  failures   = suite.count_failures
  errors     = suite.count_errors
  skips      = suite.count_skips

  bar = '=' * 78
  # @FIXME: Remove this, since Colorize already take care of colorize?
  if colorize?
    bar = if pass == total then Colorize.green(bar)
          else Colorize.red(bar) end
  end

  # @FIXME: Should we add suite.runtime, instead if this lame time calculations?
  tally = [total, assertions, (Time.new - @time)]

  io.puts bar
  io.puts "  pass: %d,  fail: %d,  error: %d, skip: %d" % [passes, failures, errors, skips]
  io.puts "  total: %d tests with %d assertions in %f seconds" % tally
  io.puts bar
end

#finish_test(test) ⇒ Object



80
81
82
83
# File 'lib/turn/reporters/cue_reporter.rb', line 80

def finish_test(test)
  $stdout = STDOUT
  $stderr = STDERR
end

#pass(message = nil) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/turn/reporters/cue_reporter.rb', line 38

def pass(message=nil)
  io.puts " #{PASS}"
  if message
    message = Colorize.green(message)
    message = message.to_s.tabto(8)
    io.puts(message)
  end
end

#show_captured_outputObject



85
86
87
88
# File 'lib/turn/reporters/cue_reporter.rb', line 85

def show_captured_output
  show_captured_stdout
  show_captured_stderr
end

#show_captured_stderrObject



99
100
101
102
103
104
105
106
# File 'lib/turn/reporters/cue_reporter.rb', line 99

def show_captured_stderr
  @stderr.rewind
  return if @stderr.eof?
  STDOUT.puts(<<-output.tabto(8))
\nSTDERR:
#{@stderr.read}
  output
end

#show_captured_stdoutObject



90
91
92
93
94
95
96
97
# File 'lib/turn/reporters/cue_reporter.rb', line 90

def show_captured_stdout
  @stdout.rewind
  return if @stdout.eof?
  STDOUT.puts(<<-output.tabto(8))
\nSTDOUT:
#{@stdout.read}
  output
end

#skip(exception, message = nil) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/turn/reporters/cue_reporter.rb', line 71

def skip(exception, message=nil)
  message = message || exception.to_s
  io.puts("#{SKIP}")
  io.puts(message) #if message

  #prompt
end

#start_case(kase) ⇒ Object



21
22
23
# File 'lib/turn/reporters/cue_reporter.rb', line 21

def start_case(kase)
  io.puts(kase.name)
end

#start_suite(suite) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/turn/reporters/cue_reporter.rb', line 11

def start_suite(suite)
  @suite = suite
  @time  = Time.now
  @stdout = StringIO.new
  @stderr = StringIO.new
  #files = suite.collect{ |s| s.file }.join(' ')
  io.puts "Loaded suite #{suite.name}"
  #io.puts "Started"
end

#start_test(test) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/turn/reporters/cue_reporter.rb', line 25

def start_test(test)
  #if @file != test.file
  #  @file = test.file
  #  io.puts(test.file)
  #end
  name = naturalized_name(test)
  io.print Colorize.blue("    %-69s" % name)
  $stdout = @stdout
  $stderr = @stderr
  $stdout.rewind
  $stderr.rewind
end