Class: XCPretty::JUnit

Inherits:
Object
  • Object
show all
Includes:
FormatMethods
Defined in:
lib/xcpretty/reporters/junit.rb

Constant Summary collapse

FILEPATH =
'build/reports/junit.xml'

Constants included from FormatMethods

FormatMethods::EMPTY

Instance Method Summary collapse

Methods included from FormatMethods

#format_analyze, #format_build_target, #format_check_dependencies, #format_clean, #format_clean_remove, #format_clean_target, #format_codesign, #format_compile, #format_compile_command, #format_compile_error, #format_compile_xib, #format_copy_strings_file, #format_cpresource, #format_duplicate_symbols, #format_error, #format_generate_dsym, #format_libtool, #format_linking, #format_pbxcp, #format_phase_script_execution, #format_preprocess, #format_process_info_plist, #format_process_pch, #format_test_run_finished, #format_test_run_started, #format_test_suite_started, #format_test_summary, #format_tiffutil, #format_touch, #format_undefined_symbols

Constructor Details

#initialize(options) ⇒ JUnit

Returns a new instance of JUnit.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xcpretty/reporters/junit.rb', line 17

def initialize(options)
  load_dependencies
  @filepath  = options[:path] || FILEPATH
  @directory = `pwd`.strip
  @document  = REXML::Document.new
  @document << REXML::XMLDecl.new('1.0','UTF-8')
  @document.add_element('testsuites')
  @parser    = Parser.new(self)
  @total_tests = 0
  @total_fails = 0
end

Instance Method Details

#finishObject



60
61
62
63
64
65
# File 'lib/xcpretty/reporters/junit.rb', line 60

def finish
  set_test_counters
  @document.root.attributes['tests'] = @total_tests
  @document.root.attributes['failures'] = @total_fails
  write_report_file
end

#format_failing_test(classname, test_case, reason, file) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/xcpretty/reporters/junit.rb', line 49

def format_failing_test(classname, test_case, reason, file)
  test_node = suite(classname).add_element('testcase')
  test_node.attributes['classname'] = classname
  test_node.attributes['name']      = test_case
  fail_node = test_node.add_element('failure')
  fail_node.attributes['message'] = reason
  fail_node.text = file.sub(@directory + '/', '')
  @test_count += 1
  @fail_count += 1
end

#format_passing_test(classname, test_case, time) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/xcpretty/reporters/junit.rb', line 33

def format_passing_test(classname, test_case, time)
  test_node = suite(classname).add_element('testcase')
  test_node.attributes['classname'] = classname
  test_node.attributes['name']      = test_case
  test_node.attributes['time']      = time
  @test_count += 1
end

#format_pending_test(classname, test_case) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/xcpretty/reporters/junit.rb', line 41

def format_pending_test(classname, test_case)
  test_node = suite(classname).add_element('testcase')
  test_node.attributes['classname'] = classname
  test_node.attributes['name']      = test_case
  test_node.add_element('skipped')
  @test_count += 1
end

#handle(line) ⇒ Object



29
30
31
# File 'lib/xcpretty/reporters/junit.rb', line 29

def handle(line)
  @parser.parse(line)
end

#load_dependenciesObject



7
8
9
10
11
12
13
14
15
# File 'lib/xcpretty/reporters/junit.rb', line 7

def load_dependencies
  unless @@loaded ||= false
    require 'fileutils'
    require 'pathname'
    require 'rexml/document'
    require 'rexml/formatters/pretty'
    @@loaded = true
  end
end