Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/rubocop/formatter/junit_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
module RuboCop
module Formatter
class JUnitFormatter < BaseFormatter

# This gives all cops - we really want all _enabled_ cops, but
# that is difficult to obtain - no access to config object here.
COPS = Cop::Cop.all

def started(target_file)
@document = REXML::Document.new.tap do |d|
d << REXML::XMLDecl.new
Expand All @@ -20,16 +15,16 @@ def started(target_file)

def file_finished(file, offences)
# One test case per cop per file
COPS.each do |cop|
offences.group_by(&:cop_name).each do |cop_name, offences|
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
f.attributes['name'] = 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|
offences.each do |offence|
REXML::Element.new('failure', f).tap do |e|
e.attributes['type'] = cop.cop_name
e.attributes['type'] = cop_name
e.attributes['message'] = offence.message
e.add_text offence.location.to_s
end
Expand Down