Class: Nucop::Formatters::JUnitFormatter
- Inherits:
-
RuboCop::Formatter::BaseFormatter
- Object
- RuboCop::Formatter::BaseFormatter
- Nucop::Formatters::JUnitFormatter
- Defined in:
- lib/nucop/formatters/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.
RuboCop::Cop::Registry.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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nucop/formatters/junit_formatter.rb', line 20 def file_finished(file, offences) # One test case per cop per file COPS.each do |cop| cop_offences = offences.select { |offence| offence.cop_name == cop.cop_name } next if cop_offences.empty? REXML::Element.new("testcase", @testsuite).tap do |f| f.attributes["classname"] = file.gsub(/\.rb\Z/, "").gsub("#{Dir.pwd}/", "").tr("/", ".") f.attributes["name"] = "Rubocop: #{cop.cop_name}" f.attributes["file"] = cop.cop_name cop_offences.each do |offence| REXML::Element.new("failure", f).tap do |e| e.add_text("#{offence.}\n\n") e.add_text(offence.location.to_s.sub("/usr/src/app/", "")) end end end end end |
#finished(_inspected_files) ⇒ Object
41 42 43 |
# File 'lib/nucop/formatters/junit_formatter.rb', line 41 def finished(_inspected_files) @document.write(output, 2) end |
#started(_target_file) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/nucop/formatters/junit_formatter.rb', line 10 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 |