Class: CI::Syntax::Tool::Format::JUnit

Inherits:
Base
  • Object
show all
Defined in:
lib/ci-syntax-tool/format/junit.rb

Overview

CI::Syntax::Tool::Format::Progress

Prints a dot for each 
API you need if you want to add a format.

Instance Attribute Summary collapse

Attributes inherited from Base

#out

Instance Method Summary collapse

Methods inherited from Base

descendant_classes, #lang_finished, #overall_started

Constructor Details

#initialize(io, args) ⇒ JUnit

Returns a new instance of JUnit.



16
17
18
19
20
21
# File 'lib/ci-syntax-tool/format/junit.rb', line 16

def initialize(io, args)
  super
  @doc = Nokogiri::XML::Document.new()
  @root = Nokogiri::XML::Element.new('testsuites', doc)
  doc.add_child(root)            
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



11
12
13
# File 'lib/ci-syntax-tool/format/junit.rb', line 11

def doc
  @doc
end

#rootObject (readonly)

Returns the value of attribute root.



12
13
14
# File 'lib/ci-syntax-tool/format/junit.rb', line 12

def root
  @root
end

#testcaseObject (readonly)

Equiv to file



14
15
16
# File 'lib/ci-syntax-tool/format/junit.rb', line 14

def testcase
  @testcase
end

#testsuiteObject (readonly)

Equiv to lang



13
14
15
# File 'lib/ci-syntax-tool/format/junit.rb', line 13

def testsuite
  @testsuite
end

Instance Method Details

#file_finished(file_result) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/ci-syntax-tool/format/junit.rb', line 35

def file_finished(file_result)
  file_result.issues.each do |issue|
    failure = Nokogiri::XML::Element.new('failure', doc)
    failure['type'] = issue.level.to_s
    message = Nokogiri::XML::CDATA.new(doc, issue.cooked_message || issue.raw_message)
    failure.add_child(message)
    testcase.add_child(failure)
  end
end

#file_started(file_result) ⇒ Object



29
30
31
32
33
# File 'lib/ci-syntax-tool/format/junit.rb', line 29

def file_started(file_result)
  @testcase = Nokogiri::XML::Element.new('testcase', doc)
  testcase['name'] = file_result.path.gsub('/','_').gsub('.','_')
  testsuite.add_child(testcase)
end

#lang_started(lang_result) ⇒ Object



23
24
25
26
27
# File 'lib/ci-syntax-tool/format/junit.rb', line 23

def lang_started(lang_result)
  @testsuite = Nokogiri::XML::Element.new('testsuite', doc)
  testsuite['name'] = lang_result.language_name
  root.add_child(testsuite)
end

#overall_finished(overall_result) ⇒ Object



45
46
47
48
# File 'lib/ci-syntax-tool/format/junit.rb', line 45

def overall_finished(overall_result)
  out.write doc.to_s
  out.flush
end