Class: MinitestLog

Inherits:
Object
  • Object
show all
Includes:
Minitest::Assertions, REXML, VerdictAssertion
Defined in:
lib/minitest_log.rb,
lib/minitest_log/version.rb

Defined Under Namespace

Classes: DuplicateVerdictIdError, Element, IllegalElementNameError, IllegalNewError, MinitestLogError, NoBlockError

Constant Summary collapse

VERSION =
'1.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VerdictAssertion

#verdict_assert?, #verdict_assert_empty?, #verdict_assert_equal?, #verdict_assert_in_delta?, #verdict_assert_in_epsilon?, #verdict_assert_includes?, #verdict_assert_instance_of?, #verdict_assert_kind_of?, #verdict_assert_match?, #verdict_assert_nil?, #verdict_assert_operator?, #verdict_assert_output?, #verdict_assert_predicate?, #verdict_assert_raises?, #verdict_assert_respond_to?, #verdict_assert_same?, #verdict_assert_silent?, #verdict_assert_throws?, #verdict_refute?, #verdict_refute_empty?, #verdict_refute_equal?, #verdict_refute_in_delta?, #verdict_refute_in_epsilon?, #verdict_refute_includes?, #verdict_refute_instance_of?, #verdict_refute_kind_of?, #verdict_refute_match?, #verdict_refute_nil?, #verdict_refute_operator?, #verdict_refute_predicate?, #verdict_refute_respond_to?, #verdict_refute_same?

Methods included from Minitest::Assertions

diff

Constructor Details

#initialize(file_path, options = Hash.new) ⇒ MinitestLog

Returns a new instance of MinitestLog.

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/minitest_log.rb', line 33

def initialize(file_path, options=Hash.new)
  raise NoBlockError.new('No block given for MinitestLog#new.') unless (block_given?)
  self.file_path = file_path
  handle_options(options)
  do_log do
    begin
      yield self
    rescue => x
      handle_exception(x)
    end
  end
  create_xml_log
end

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions.



15
16
17
# File 'lib/minitest_log.rb', line 15

def assertions
  @assertions
end

#backtrace_filterObject

Returns the value of attribute backtrace_filter.



15
16
17
# File 'lib/minitest_log.rb', line 15

def backtrace_filter
  @backtrace_filter
end

#countsObject

Returns the value of attribute counts.



15
16
17
# File 'lib/minitest_log.rb', line 15

def counts
  @counts
end

#error_verdictObject

Returns the value of attribute error_verdict.



15
16
17
# File 'lib/minitest_log.rb', line 15

def error_verdict
  @error_verdict
end

#fileObject

Returns the value of attribute file.



15
16
17
# File 'lib/minitest_log.rb', line 15

def file
  @file
end

#file_pathObject

Returns the value of attribute file_path.



15
16
17
# File 'lib/minitest_log.rb', line 15

def file_path
  @file_path
end

#root_nameObject

Returns the value of attribute root_name.



15
16
17
# File 'lib/minitest_log.rb', line 15

def root_name
  @root_name
end

#summaryObject

Returns the value of attribute summary.



15
16
17
# File 'lib/minitest_log.rb', line 15

def summary
  @summary
end

#verdict_idsObject

Returns the value of attribute verdict_ids.



15
16
17
# File 'lib/minitest_log.rb', line 15

def verdict_ids
  @verdict_ids
end

#xml_indentationObject

Returns the value of attribute xml_indentation.



15
16
17
# File 'lib/minitest_log.rb', line 15

def xml_indentation
  @xml_indentation
end

Instance Method Details

#comment(text) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/minitest_log.rb', line 54

def comment(text)
  if text.match("\n")
    # Separate text from containing punctuation.
    put_element('comment') do
      cdata("\n#{text}\n")
    end
  else
    put_element('comment', text)
  end
  nil
end

#put_data(name, obj) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/minitest_log.rb', line 145

def put_data(name, obj)
  case
  when obj.kind_of?(String)
    put_string(name, obj)
  when obj.respond_to?(:each_pair)
    put_each_pair(name, obj)
  when obj.respond_to?(:each_with_index)
    put_each_with_index(name, obj)
  when obj.respond_to?(:each)
    put_each(name, obj)
  when obj.respond_to?(:to_s)
    put_to_s(name, obj)
  when obj.respond_to?(:inspect)
    put_inspect(name, obj)
  when obj.respond_to?(:__id__)
    put_id(name, obj)
  else
    message = "Object does not respond to method :__id__: name=#{name}, obj=#{obj}"
    raise ArgumentError.new(message)
  end
end

#put_each(name, obj) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/minitest_log.rb', line 94

def put_each(name, obj)
  lines = ['']
  obj.each do |item|
    lines.push(item)
  end
  attrs = {
      :name => name,
      :class => obj.class,
      :method => ':each',
  }
  add_attr_if(attrs, obj, :size)
  put_element('data', attrs) do
    put_pre(lines.join("\n"))
  end
  nil
end

#put_each_pair(name, obj) ⇒ Object Also known as: put_hash



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/minitest_log.rb', line 111

def put_each_pair(name, obj)
  lines = ['']
  obj.each_pair do |key, value|
    lines.push(format('%s => %s', key, value))
  end
  attrs = {
      :name => name,
      :class => obj.class,
      :method => ':each_pair',
  }
  add_attr_if(attrs, obj, :size)
  put_element('data', attrs) do
    put_pre(lines.join("\n"))
  end
  nil
end

#put_each_with_index(name, obj) ⇒ Object Also known as: put_array, put_set



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/minitest_log.rb', line 75

def put_each_with_index(name, obj)
  lines = ['']
  obj.each_with_index do |item, i|
    lines.push(format('%d: %s', i, item.to_s))
  end
  attrs = {
      :name => name,
      :class => obj.class,
      :method => ':each_with_index',
  }
  add_attr_if(attrs, obj, :size)
  put_element('data', attrs) do
    put_pre(lines.join("\n"))
  end
  nil
end

#put_element(element_name = 'element', *args) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/minitest_log.rb', line 66

def put_element(element_name = 'element', *args)
  conditioned_element_name = condition_element_name(element_name, caller[0])
  if block_given?
    Element.new(self, conditioned_element_name, *args, &Proc.new)
  else
    Element.new(self, conditioned_element_name, *args)
  end
end

#put_id(name, obj) ⇒ Object



141
142
143
# File 'lib/minitest_log.rb', line 141

def put_id(name, obj)
  put_element('data', :name => name, :class => obj.class, :id => obj.__id__)
end

#put_inspect(name, obj) ⇒ Object



137
138
139
# File 'lib/minitest_log.rb', line 137

def put_inspect(name, obj)
  put_element('data',  obj.inspect, :name => name, :class => obj.class, :method => ':inspect')
end

#put_pre(text, verbatim = false) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/minitest_log.rb', line 167

def put_pre(text, verbatim = false)
  if verbatim
    put_cdata(text)
  else
    t = text.clone
    until t.start_with?("\n")
      t = "\n" + t
    end
    until t.end_with?("\n\n")
      t = t + "\n"
    end
    put_cdata(t)
  end
end

#put_string(name, obj) ⇒ Object



133
134
135
# File 'lib/minitest_log.rb', line 133

def put_string(name, obj)
  put_element('data',  obj.to_s, :name => name, :class => obj.class, :size => obj.size)
end

#put_to_s(name, obj) ⇒ Object



129
130
131
# File 'lib/minitest_log.rb', line 129

def put_to_s(name, obj)
  put_element('data',  obj.to_s, :name => name, :class => obj.class, :method => ':to_s')
end

#section(name, *args) ⇒ Object



47
48
49
50
51
52
# File 'lib/minitest_log.rb', line 47

def section(name, *args)
  put_element('section', {:name => name}, *args) do
    yield if block_given?
  end
  nil
end