Skip to content

Commit

Permalink
include total violation count in ViolationFormatter output
Browse files Browse the repository at this point in the history
* When adding cane to a legacy project and ratching down the
  max_violations setting it's handy to know what value to set
* At the moment I need to manually sum the violation count for each
  grouping
  • Loading branch information
yob committed Jun 15, 2012
1 parent 2e684a9 commit ced755f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/cane/violation_formatter.rb
Expand Up @@ -11,11 +11,15 @@ def to_s
grouped_violations.map do |description, violations|
format_group_header(description, violations) +
format_violations(violations)
end.flatten.join("\n") + "\n\n"
end.flatten.join("\n") + "\n\n" + totals + "\n\n"
end

protected

def totals
"Total Violations: #{violations.count}"
end

def format_group_header(description, violations)
["", "%s (%i):" % [description, violations.length], ""]
end
Expand Down
6 changes: 6 additions & 0 deletions spec/violation_formatter_spec.rb
Expand Up @@ -13,4 +13,10 @@ def violation(description)
it 'includes number of violations in the group header' do
described_class.new([violation("FAIL")]).to_s.should include("(1)")
end

it 'includes total number of violations' do
violations = [violation("FAIL1"),violation("FAIL2")]
result = described_class.new(violations).to_s
result.should include("Total Violations: 2")
end
end

0 comments on commit ced755f

Please sign in to comment.