Class: Webspicy::Tester::Reporter::JunitXmlFile

Inherits:
Webspicy::Tester::Reporter show all
Defined in:
lib/webspicy/tester/reporter/junit_xml_file.rb

Constant Summary collapse

TPL =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites\n  disabled=\"{{counts.disabled}}\"\n  errors=\"{{counts.errors}}\"\n  failures=\"{{counts.failures}}\"\n  tests=\"{{counts.total}}\"\n  time=\"{{time}}s\"\n>\n  {{#testsuites}}\n    <testsuite\n      name=\"{{name}}\"\n      tests=\"{{counts.total}}\"\n      errors=\"{{counts.errors}}\"\n      failures=\"{{counts.failures}}\"\n      time=\"{{time}}s\"\n    >\n      {{#testcases}}\n        <testcase\n          name=\"{{name}}\"\n          assertions=\"{{assert}}\"\n          classname=\"{{classname}}\"\n          status=\"\"\n          time=\"{{time}}s\"\n        >\n          {{#errors}}\n            <error\n              message=\"{{message}}\"\n              type=\"{{type}}\"\n            ></error>\n          {{/errors}}\n          {{#failures}}\n            <failure\n              message=\"{{message}}\"\n              type=\"{{type}}\"\n              ></failure>\n          {{/failures}}\n        </testcase>\n      {{/testcases}}\n    </testsuite>\n  {{/testsuites}}\n</testsuites>\n"

Constants inherited from Webspicy::Tester::Reporter

ErrorCount, HOOKS

Instance Attribute Summary collapse

Attributes inherited from Webspicy::Tester::Reporter

#io, #tester

Instance Method Summary collapse

Methods inherited from Webspicy::Tester::Reporter

#find, #init

Methods included from Support::Colorize

colorize, colorize_error, colorize_highlight, colorize_section, colorize_success

Constructor Details

#initialize(path_or_io = STDOUT) ⇒ JunitXmlFile

Returns a new instance of JunitXmlFile.



50
51
52
53
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 50

def initialize(path_or_io = STDOUT)
  @path_or_io = path_or_io
  path_or_io.parent.mkdir_p if path_or_io.is_a?(Path)
end

Instance Attribute Details

#template_dataObject (readonly)

Returns the value of attribute template_data.



55
56
57
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 55

def template_data
  @template_data
end

#timer_allObject (readonly)

Returns the value of attribute timer_all.



55
56
57
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 55

def timer_all
  @timer_all
end

#timer_specificationObject (readonly)

Returns the value of attribute timer_specification.



55
56
57
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 55

def timer_specification
  @timer_specification
end

#timer_testcaseObject (readonly)

Returns the value of attribute timer_testcase.



55
56
57
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 55

def timer_testcase
  @timer_testcase
end

Instance Method Details

#after_allObject



65
66
67
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 65

def after_all
  template_data.time = Time.now - timer_all
end

#before_allObject



57
58
59
60
61
62
63
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 57

def before_all
  @timer_all = Time.now
  @template_data = OpenStruct.new({
    counts: Hash.new{|h,k| h[k] = 0 },
    testsuites: []
  })
end

#before_specificationObject



69
70
71
72
73
74
75
76
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 69

def before_specification
  @timer_specification = Time.now
  template_data.testsuites << OpenStruct.new({
    :name => specification.name,
    :counts => Hash.new{|h,k| h[k] = 0 },
    :testcases => []
  })
end

#before_test_caseObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 95

def before_test_case
  @timer_testcase = Time.now
  template_data.testsuites[-1].testcases << OpenStruct.new({
    :name => test_case.description,
    :assert => test_case.assert.length,
    :classname => test_case.class.name.to_s.gsub(/::/, "."),
    :failures => [],
    :errors => [],
  })
  template_data.counts[:total] += 1
  template_data.testsuites[-1].counts[:total] += 1
end

#check_error(check, ex) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 121

def check_error(check, ex)
  template_data.testsuites[-1].testcases[-1].errors << OpenStruct.new({
    :type => check.class.name,
    :message => ex.message
  })
  template_data.counts[:errors] += 1
  template_data.testsuites[-1].counts[:errors] += 1
end

#check_failure(check, ex) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 112

def check_failure(check, ex)
  template_data.testsuites[-1].testcases[-1].failures << OpenStruct.new({
    :type => check.class.name,
    :message => ex.message
  })
  template_data.counts[:failures] += 1
  template_data.testsuites[-1].counts[:failures] += 1
end

#reportObject



130
131
132
133
134
135
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 130

def report
  require 'mustache'
  with_io do |io|
    io << Mustache.render(TPL, template_data)
  end
end

#spec_file_error(e) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 82

def spec_file_error(e)
  template_data.testsuites[-1].testcases << OpenStruct.new({
    :name => "Specification can be loaded",
    :assert => 1,
    :classname => "Webspicy.Specification",
    :failures => [],
    :errors => [OpenStruct.new({
      :type => e.class,
      :message => e.message
    })]
  })
end

#specification_doneObject



78
79
80
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 78

def specification_done
  template_data.testsuites[-1].time = Time.now - timer_specification
end

#test_case_doneObject



108
109
110
# File 'lib/webspicy/tester/reporter/junit_xml_file.rb', line 108

def test_case_done
  template_data.testsuites[-1].testcases[-1].time = Time.now - timer_testcase
end