Class: QED::Reporter::TapY

Inherits:
Abstract show all
Defined in:
lib/qed/reporter/tapy.rb

Overview

TAP-Y Reporter

NOTE: I suppose techincally that each TAP-Y test should be an assertion, but that's a whole other ball of wax, and would require AE to remember every assertion made. It also would have no means of providing an upfront count.

Constant Summary

Constants inherited from Abstract

Abstract::DEFAULT_TRACE_COUNT, Abstract::INFO_SIGNAL, Abstract::INTERNALS

Instance Attribute Summary

Attributes inherited from Abstract

#io, #record, #session

Instance Method Summary collapse

Methods inherited from Abstract

After, Before, When, #after_demo, #after_eval, #after_import, #after_proc, #after_step, #before_demo, #before_eval, #before_import, #before_proc, #before_step, #call, #clean_backtrace, #code_snippet, #count_demo, #count_error, #count_fail, #count_pass, #count_step, #demos, #errors, #eval, #fails, #file_and_line, #file_line, #get_tally, #import, #initialize, #localize_file, #omits, #passes, #print_tally, #print_time, #proc, #relative_file, #rule, #sane_backtrace, #source, #step, #steps, #structured_code_snippet, #success?, #trace?, #trace_count

Constructor Details

This class inherits a constructor from QED::Reporter::Abstract

Instance Method Details

#after_session(session) ⇒ Object


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/qed/reporter/tapy.rb', line 165

def after_session(session)
  pass_size = steps.size - (fails.size + errors.size + omits.size)

  data = {
    'type'   => 'final',
    'time' => time_since_start,
    'counts' => {
       'total' => steps.size,
       'pass'  => pass_size,
       'fail'  => fails.size,
       'error' => errors.size,
       'omit'  => omits.size,
       'todo'  => 0
     }
  }

  io.puts data.to_yaml
end

#before_session(session) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/qed/reporter/tapy.rb', line 16

def before_session(session)
  @start_time = Time.now

  data = {
    'type'  => 'suite',
    'start' => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
    'count' => session.total_step_count,
    'rev'   => 2
  }
  io.puts data.to_yaml
end

#demo(demo) ⇒ Object

TODO: Handle cases by file or by headers?


29
30
31
32
33
34
35
36
37
# File 'lib/qed/reporter/tapy.rb', line 29

def demo(demo)
  data = {
    'type'    => 'case',
    'subtype' => 'demo',
    'label'   => localize_file(demo.file),
    'level'   => 0
  }
  io.puts data.to_yaml
end

#error(step, exception) ⇒ Object


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/qed/reporter/tapy.rb', line 129

def error(step, exception)
  super(step, exception)

  backtrace = sane_backtrace(exception)

  file, line = file_line(backtrace)
  file = localize_file(file)

  snippet = structured_code_snippet(exception, bredth=3)
  source  = snippet.map{ |h| h.values.first }[snippet.size / 2].strip

  data = {
    'type'        => 'test',
    'subtype'     => 'step',
    'status'      => 'error',
    'label'       => step.explain.strip,
    'file'        => localize_file(step.file),
    'line'        => step.explain_lineno,
    #'returned'    => nil,
    #'expected'    => nil,
    'time'        => time_since_start,
    'exception'   => {
      'message'   => assertion.message, #unansi
      'class'     => assertion.class.name,
      'file'      => file,
      'line'      => line,
      'source'    => source,
      'snippet'   => snippet,
      'backtrace' => backtrace
    }
  }

  io.puts data.to_yaml
end

#fail(step, assertion) ⇒ Object


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/qed/reporter/tapy.rb', line 93

def fail(step, assertion)
  super(step, assertion)

  backtrace = sane_backtrace(assertion)

  file, line = file_line(backtrace)
  file = localize_file(file)

  snippet = structured_code_snippet(assertion, bredth=3)
  source  = snippet.map{ |h| h.values.first }[snippet.size / 2].strip

  data = {
    'type'        => 'test',
    'subtype'     => 'step',
    'status'      => 'fail',
    'label'       => step.explain.strip,
    'file'        => localize_file(step.file),
    'line'        => step.explain_lineno,
    #'returned'    => nil,
    #'expected'    => nil,
    'time'        => time_since_start,
    'exception'   => {
      'message'   => assertion.message, #unansi
      'class'     => assertion.class.name,
      'file'      => file,
      'line'      => line,
      'source'    => source,
      'snippet'   => snippet,
      'backtrace' => backtrace
    }
  }

  io.puts data.to_yaml
end

#pass(step) ⇒ Object

TODO:

How to get the line number so we can do proper snippets?


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/qed/reporter/tapy.rb', line 41

def pass(step)
  super(step)

  source_line = lines = step.text.split("\n")

  #snip, l = [], step.line
  #lines.map do |line|
  #  snip << { (l += 1) => line }
  #end

  #if step.header?
  #  data = {
  #    'type'        => 'note',
  #    'description' => step.text, #.strip,
  #  }

  data = {
      'type'    => 'test',
      'subtype' => 'step',
      'status'  => 'pass',
      'label'   => step.text.strip,
      'file'    => localize_file(step.file),
      'line'    => step.lineno,
      'time'    => time_since_start
  }

      #'returned' => nil,
      #'expected' => nil,

  if step.example?
    if step.code?
      data.merge!(
        'source'  => step.example_lines.first.last.strip,
        'snippet' => step.example_lines.map{ |n, l| {n => l.rstrip} }
      )
    else
      data.merge!( 
        'source'  => step.example_lines.first.last.strip,
        'snippet' => step.example_lines.map{ |n, l| {n => l.rstrip} }
      )
    end
  else
    #data.merge!(
    #  'source'  => step.explain_lines.first.first,
    #  'snippet' => step.sample_text
    #)
  end

  io.puts data.to_yaml
end

#time_since_startObject (private)


187
188
189
# File 'lib/qed/reporter/tapy.rb', line 187

def time_since_start
  Time.now - @start_time
end