Class: Brakeman::Report::JUnit

Inherits:
Base
  • Object
show all
Defined in:
lib/brakeman/report/report_junit.rb

Constant Summary

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP, Util::SIMPLE_LITERALS

Instance Attribute Summary

Attributes inherited from Base

#checks, #tracker

Instance Method Summary collapse

Methods inherited from Base

#absolute_paths?, #all_warnings, #context_for, #controller_information, #controller_warnings, #filter_warnings, #generic_warnings, #github_url, #ignored_warnings, #initialize, #model_warnings, #number_of_templates, #rails_version, #template_warnings, #warning_file, #warnings_summary

Methods included from Util

#all_literals?, #array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #hash_values, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #recurse_check?, #regexp?, #remove_kwsplat, #request_headers?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #simple_literal?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore

Constructor Details

This class inherits a constructor from Brakeman::Report::Base

Instance Method Details

#generate_reportObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/brakeman/report/report_junit.rb', line 6

def generate_report
  io = StringIO.new
  doc = REXML::Document.new
  doc.add REXML::XMLDecl.new '1.0', 'UTF-8'

  test_suites = REXML::Element.new 'testsuites'

  i = 0
  all_warnings
    .map { |warning| [warning.file, [warning]] }
    .reduce({}) { |entries, entry|
      key, value = entry
      entries[key] = entries[key] ? entries[key].concat(value) : value
      entries
    }
    .each { |file, warnings|
      i += 1
      test_suite = test_suites.add_element 'testsuite'
      test_suite.add_attribute 'id', i
      test_suite.add_attribute 'package', 'brakeman'
      test_suite.add_attribute 'file', file.relative
      test_suite.add_attribute 'timestamp', tracker.start_time.strftime('%FT%T')
      test_suite.add_attribute 'tests', checks.checks_run.length
      test_suite.add_attribute 'failures', warnings.length
      test_suite.add_attribute 'errors', '0'
      test_suite.add_attribute 'time', '0'

      warnings.each { |warning|
        test_case = test_suite.add_element 'testcase'
        test_case.add_attribute 'name', warning.check.sub(/^Brakeman::/, '')
        test_case.add_attribute 'file', file.relative
        test_case.add_attribute 'line', warning.line if warning.line
        test_case.add_attribute 'time', '0'

        failure = test_case.add_element 'failure'
        failure.add_attribute 'message', warning.message
        failure.add_attribute 'type', warning.warning_type
        failure.add_text warning.to_s
      }
    }

  doc.add test_suites
  doc.write io
  io.string
end