Class: RuboCop::Formatter::JUnitFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- RuboCop::Formatter::JUnitFormatter
- Defined in:
- lib/rubocop/formatter/junit_formatter.rb
Constant Summary collapse
- COPS =
This gives all cops - we really want all enabled cops, but that is difficult to obtain - no access to config object here.
Cop::Cop.all
Instance Method Summary collapse
- #file_finished(file, offences) ⇒ Object
- #finished(inspected_files) ⇒ Object
- #started(target_file) ⇒ Object
Instance Method Details
#file_finished(file, offences) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/formatter/junit_formatter.rb', line 21 def file_finished(file, offences) # One test case per cop per file COPS.each do |cop| REXML::Element.new('testcase', @testsuite).tap do |f| f.attributes['classname'] = file.gsub(/\.rb\Z/, '').gsub("#{Dir.pwd}/", '').gsub('/', '.') f.attributes['name'] = cop.cop_name # One failure per offence. Zero failures is a passing test case, # for most surefire/nUnit parsers. offences.select {|offence| offence.cop_name == cop.cop_name}.each do |offence| REXML::Element.new('failure', f).tap do |e| e.attributes['type'] = cop.cop_name e.attributes['message'] = offence. e.add_text offence.location.to_s end end end end end |
#finished(inspected_files) ⇒ Object
41 42 43 |
# File 'lib/rubocop/formatter/junit_formatter.rb', line 41 def finished(inspected_files) @document.write(output, 2) end |
#started(target_file) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/rubocop/formatter/junit_formatter.rb', line 11 def started(target_file) @document = REXML::Document.new.tap do |d| d << REXML::XMLDecl.new end @testsuites = REXML::Element.new('testsuites', @document) @testsuite = REXML::Element.new('testsuite', @testsuites).tap do |el| el.add_attributes('name' => 'rubocop') end end |