Class: Test::Reporters::AbstractHash

Inherits:
Abstract
  • Object
show all
Defined in:
lib/rubytest/format/abstract_hash.rb

Overview

Structured records used by the internal test reporter.

Direct Known Subclasses

Tapj, Tapy, Test

Instance Attribute Summary

Attributes inherited from Abstract

#runner

Instance Method Summary collapse

Methods inherited from Abstract

inherited, #initialize, registry

Constructor Details

This class inherits a constructor from Test::Reporters::Abstract

Instance Method Details

#begin_case(test_case) ⇒ Hash

Returns:

  • (Hash)


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rubytest/format/abstract_hash.rb', line 60

def begin_case(test_case)
  h = {}
  h['type' ] = 'case'
  h['level'] = @case_level

  merge_subtype h, test_case
  merge_setup   h, test_case
  merge_label   h, test_case

  @case_level += 1

  return h
end

#begin_suite(suite) ⇒ Hash

Returns:

  • (Hash)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubytest/format/abstract_hash.rb', line 36

def begin_suite(suite)
  require 'yaml'
  require 'stringio'

  @start_time = Time.now
  @case_level = 0
  @test_index = 0

  now = Time.now.strftime('%Y-%m-%d %H:%M:%S')

  h = {
    'type'  => 'suite',
    'start' => now,
    'count' => total_count(suite)
  }

  h['seed'] = suite.seed if suite.respond_to?(:seed)

  return h
end

#begin_test(test) ⇒ Object



75
76
77
# File 'lib/rubytest/format/abstract_hash.rb', line 75

def begin_test(test)
  @test_index += 1
end

#capture_output? ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rubytest/format/abstract_hash.rb', line 9

def capture_output?
  true
end

#end_case(test_case) ⇒ Object



189
190
191
# File 'lib/rubytest/format/abstract_hash.rb', line 189

def end_case(test_case)
  @case_level -= 1
end

#end_suite(suite) ⇒ Hash

Returns:

  • (Hash)


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/rubytest/format/abstract_hash.rb', line 196

def end_suite(suite)
  h = {
    'type'  => 'final',
    'time'  => @summary.elapsed,
    'counts' => {
      'total' => @summary.total,
      'pass'  => @summary.counts[:pass],
      'fail'  => @summary.counts[:fail],
      'error' => @summary.counts[:error],
      'omit'  => @summary.counts[:skip],
      'todo'  => @summary.counts[:todo]
    }
  }
  return h
end

#end_test(test) ⇒ Object



184
185
186
# File 'lib/rubytest/format/abstract_hash.rb', line 184

def end_test(test)
  super(test)
end

#error(test, exception) ⇒ Hash

Returns:

  • (Hash)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rubytest/format/abstract_hash.rb', line 142

def error(test, exception)
  h = {}
  h['type'  ] = 'test'
  h['status'] = 'error'

  merge_subtype      h, test
  merge_priority     h, test, exception
  merge_setup        h, test
  merge_label        h, test
  #merge_comparison  h, test, exception
  #merge_coverage    h, test
  merge_source       h, test
  merge_exception    h, test, exception, true
  merge_output       h
  merge_time         h

  return h
end

#fail(test, exception) ⇒ Hash

Returns:

  • (Hash)


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rubytest/format/abstract_hash.rb', line 120

def fail(test, exception)
  h = {}
  h['type'  ] = 'test'
  h['status'] = 'fail'

  merge_subtype      h, test
  merge_priority     h, test, exception
  merge_setup        h, test
  merge_label        h, test
  #merge_comparison  h, test, exception
  #merge_coverage    h, test
  merge_source       h, test
  merge_exception    h, test, exception
  merge_output       h
  merge_time         h
 
  return h
end

#finish(summary) ⇒ Object



28
29
30
31
# File 'lib/rubytest/format/abstract_hash.rb', line 28

def finish(summary)
  @summary = summary
  end_suite(summary.suite)
end

#pass(test) ⇒ Hash

Returns:

  • (Hash)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rubytest/format/abstract_hash.rb', line 100

def pass(test) #, backtrace=nil)
  h = {}
  h['type'  ] = 'test'
  h['status'] = 'pass'

  merge_subtype      h, test
  merge_setup        h, test
  merge_label        h, test
  #merge_comparison  h, test, exception
  #merge_coverage    h, test
  merge_source       h, test
  merge_output       h
  merge_time         h

  return h
end

#record(result) ⇒ Object

Return a structured record of the completed result.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubytest/format/abstract_hash.rb', line 14

def record(result)
  @current_result = result
  if result.status == :skip
    method = result.kind == :case ? :skip_case : :skip_test
    public_send(method, result.test, result.reason)
  elsif result.status == :pass
    pass(result.test)
  else
    public_send(result.status, result.test, result.exception)
  end
ensure
  @current_result = nil if result
end

#skip_case(test_case, reason = nil) ⇒ Hash

A skipped case is reported like a skipped test, as a case.

Returns:

  • (Hash)


93
94
95
# File 'lib/rubytest/format/abstract_hash.rb', line 93

def skip_case(test_case, reason=nil)
  skip_record(test_case, reason).merge('type' => 'case')
end

#skip_test(test, reason = nil) ⇒ Hash

TODO:

Maybe the terms can ultimately be reconciled.

Ruby Test use the term "skip", where as TAP-Y/J uses "omit".

Returns:

  • (Hash)


85
86
87
# File 'lib/rubytest/format/abstract_hash.rb', line 85

def skip_test(test, reason=nil)
  skip_record(test, reason)
end

#todo(test, exception) ⇒ Hash

Returns:

  • (Hash)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/rubytest/format/abstract_hash.rb', line 164

def todo(test, exception)
  h = {}
  h['type'  ]   = 'test'
  h['status']   = 'todo'

  merge_subtype      h, test
  merge_priority     h, test, exception
  merge_setup        h, test
  merge_label        h, test
  #merge_comparison  h, test, exception
  #merge_coverage    h, test
  merge_source       h, test
  merge_exception    h, test, exception
  merge_output       h
  merge_time         h

  return h
end