Class: XCPretty::JUnit

Inherits:
Reporter show all
Defined in:
lib/xcpretty/reporters/junit.rb

Constant Summary collapse

FILEPATH =
'build/reports/junit.xml'

Constants inherited from Formatter

Formatter::ASCII_ERROR, Formatter::ASCII_WARNING, Formatter::ERROR, Formatter::WARNING

Constants included from FormatMethods

FormatMethods::EMPTY

Constants included from ANSI

ANSI::COLORS, ANSI::EFFECT, ANSI::FORMATTED_MATCHER

Instance Attribute Summary

Attributes inherited from Reporter

#tests

Attributes inherited from Formatter

#parser

Attributes included from ANSI

#colorize

Instance Method Summary collapse

Methods inherited from Formatter

#format_compile_error, #format_compile_warning, #format_duplicate_symbols, #format_error, #format_file_missing_error, #format_ld_warning, #format_other, #format_test_summary, #format_undefined_symbols, #format_will_not_be_code_signed, #optional_newline, #pretty_format, #use_unicode?

Methods included from FormatMethods

#format_aggregate_target, #format_analyze, #format_analyze_target, #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_storyboard, #format_compile_warning, #format_compile_xib, #format_copy_header_file, #format_copy_plist_file, #format_copy_strings_file, #format_cpresource, #format_duplicate_symbols, #format_error, #format_file_missing_error, #format_generate_dsym, #format_ld_warning, #format_libtool, #format_linking, #format_measuring_test, #format_other, #format_pbxcp, #format_phase_script_execution, #format_phase_success, #format_preprocess, #format_process_info_plist, #format_process_pch, #format_process_pch_command, #format_shell_command, #format_test_run_finished, #format_test_suite_started, #format_test_summary, #format_tiffutil, #format_touch, #format_undefined_symbols, #format_warning, #format_write_auxiliary_files, #format_write_file

Methods included from ANSI

#ansi_parse, #applied_effects, #colorize?, #cyan, #green, #red, #strip, #white, #yellow

Constructor Details

#initialize(options) ⇒ JUnit

Returns a new instance of JUnit.



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

def initialize(options)
  super(options)
  @directory = `pwd`.strip
  @document  = REXML::Document.new
  @document << REXML::XMLDecl.new('1.0', 'UTF-8')
  @document.add_element('testsuites')
  @total_fails = 0
  @total_tests = 0
end

Instance Method Details

#finishObject



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

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

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



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

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



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

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



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

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

#format_test_run_started(name) ⇒ Object



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

def format_test_run_started(name)
  @document.root.add_attribute('name', name)
end

#handle(line) ⇒ Object



26
27
28
# File 'lib/xcpretty/reporters/junit.rb', line 26

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

#load_dependenciesObject



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

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

#write_reportObject



68
69
70
71
72
73
74
75
# File 'lib/xcpretty/reporters/junit.rb', line 68

def write_report
  formatter = REXML::Formatters::Pretty.new(2)
  formatter.compact = true
  output_file = File.open(@filepath, 'w+')
  result = formatter.write(@document, output_file)
  output_file.close
  result
end