Class: Strut::ReportJUnitFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/strut/report_junit_formatter.rb

Instance Method Summary collapse

Instance Method Details

#add_element_for_testcase(element, testcase, message, type) ⇒ Object



41
42
43
44
45
# File 'lib/strut/report_junit_formatter.rb', line 41

def add_element_for_testcase(element, testcase, message, type)
  node = testcase.add_element(element)
  node.attributes["message"] = message
  node.attributes["type"] = type
end

#add_error_for_testcase(message, testcase) ⇒ Object



37
38
39
# File 'lib/strut/report_junit_formatter.rb', line 37

def add_error_for_testcase(message, testcase)
  add_element_for_testcase("error", testcase, message, "exception")
end

#add_failure_for_testcase(message, testcase) ⇒ Object



33
34
35
# File 'lib/strut/report_junit_formatter.rb', line 33

def add_failure_for_testcase(message, testcase)
  add_element_for_testcase("failure", testcase, message, "assert")
end

#add_result_for_testcase(scenario, testcase) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/strut/report_junit_formatter.rb', line 25

def add_result_for_testcase(scenario, testcase)
  if scenario.result == SCENARIO_FAIL
    add_failure_for_testcase(scenario.message, testcase)
  elsif scenario.result == SCENARIO_ERROR
    add_error_for_testcase(scenario.message, testcase)
  end
end

#add_testcase_for_scenario(scenario, testsuite) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/strut/report_junit_formatter.rb', line 17

def add_testcase_for_scenario(scenario, testsuite)
  testcase = testsuite.add_element("testcase")
  testcase.attributes["name"] = scenario.name
  testcase.attributes["time"] = scenario.time
  testcase.attributes["classname"] = "swagger"
  add_result_for_testcase(scenario, testcase)
end

#add_testsuite(results, doc) ⇒ Object



10
11
12
13
14
15
# File 'lib/strut/report_junit_formatter.rb', line 10

def add_testsuite(results, doc)
  testsuite = doc.add_element("testsuite")
  results.each do |scenario|
    add_testcase_for_scenario(scenario, testsuite)
  end
end

#format(report) ⇒ Object



3
4
5
6
7
8
# File 'lib/strut/report_junit_formatter.rb', line 3

def format(report)
  doc = REXML::Document.new("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
  results = report.scenario_results
  add_testsuite(results, doc)
  doc.to_s
end