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.

Instance Attribute Summary

Attributes inherited from Abstract

#io, #record, #session

Instance Method Summary collapse

Methods inherited from Abstract

After, Before, When, #after_code, #after_data, #after_demo, #after_desc, #after_head, #after_step, #before_code, #before_data, #before_demo, #before_desc, #before_head, #before_session, #before_step, #code, #count_code, #count_demo, #count_desc, #count_error, #count_fail, #count_pass, #data, #demo, #demos, #errors, #fails, #import, #initialize, #load, #omits, #passes, #steps, #trace?, #unload, #update, #when

Constructor Details

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

Instance Method Details

#after_session(session) ⇒ Object

def report_macro(step)

txt = step.to_s.tabto(2)
txt[0,1] = "*"
io.puts txt
#io.puts
#io.puts "#{step}".ansi(:magenta)

end



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/qed/reporter/tapy.rb', line 196

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

  data = {
    'type'  => 'footer',
    'tally' => {
       'pass'    => pass_size,
       'fail'    => fails.size,
       'error'   => errors.size,
       'omit'    => omits.size,
       'pending' => 0
     },
     'time' => time_since_start
  }

  io.puts data.to_yaml
end

#desc(step) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/qed/reporter/tapy.rb', line 26

def desc(step)
  #data = {
  #  'type'        => 'note',
  #  'description' => step.to_s.strip
  #}
  #io.puts data.to_yaml
end

#error(step, exception) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/qed/reporter/tapy.rb', line 109

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

  backtrace = sane_backtrace(exception)

  file, line = file_line(backtrace)

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

  data = {
    'type'        => 'test',
    'status'      => 'error',
    'description' => step.text.strip,
    'file'        => file,
    'line'        => line,
    'message'     => exception.to_s.unansi,
    #'returned'    => nil,
    #'expected'    => nil,
    'backtrace'   => backtrace,
    'source'      => source,
    'snippet'     => snippet,
    'time'        => time_since_start
  }

  io.puts data.to_yaml
end

#fail(step, assertion) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/qed/reporter/tapy.rb', line 81

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

  backtrace = sane_backtrace(assertion)

  file, line = file_line(backtrace)

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

  data = {
    'type'        => 'test',
    'status'      => 'fail',
    'description' => step.text.strip,
    'file'        => file,
    'line'        => line,
    'message'     => assertion.to_s.unansi,
    #'returned'    => nil,
    #'expected'    => nil,
    'source'      => source,
    'snippet'     => snippet,
    'time'        => time_since_start
  }

  io.puts data.to_yaml
end

#head(step) ⇒ Object



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

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

#pass(step) ⇒ Object

TODO:

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



36
37
38
39
40
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
# File 'lib/qed/reporter/tapy.rb', line 36

def pass(step)
  super(step)

  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,
    }
  elsif step.code?
    data = {
      'type'        => 'test',
      'status'      => 'pass',
      'description' => step.text.strip,
      #'file'        => step.file,
      #'line'        => step.line,
      #'returned'    => nil,
      #'expected'    => nil,
      'source'      => lines.first,
      'snippet'     => step.text.strip,
      'time'        => time_since_start
    }
  else
    data = {
      'type'        => 'test',
      'status'      => 'pass',
      'description' => step.text.strip,
      #'file'        => step.file,
      #'line'        => step.line,
      #'returned'    => nil,
      #'expected'    => nil,
      'source'      => lines.first,
      'snippet'     => step.text.strip,
      'time'        => time_since_start
    }
  end
  io.puts data.to_yaml
end