count controls in the summary output. Fix #852

This commit is contained in:
Victoria Jeffrey 2016-08-01 17:02:02 -04:00 committed by Kartik Null Cating-Subramanian
parent 31a7d58473
commit 6c91183995

View file

@ -87,7 +87,7 @@ class InspecRspecMiniJson < RSpec::Core::Formatters::JsonFormatter
end
class InspecRspecJson < InspecRspecMiniJson
RSpec::Core::Formatters.register self, :start, :stop
RSpec::Core::Formatters.register self, :start, :stop, :dump_summary
attr_writer :backend
def initialize(*args)
@ -133,6 +133,35 @@ class InspecRspecJson < InspecRspecMiniJson
@output_hash[:other_checks] = missing
end
def dump_summary(summary)
super(summary)
total = 0
failed = 0
skipped = 0
passed = 0
@profiles_info.each do |_name, profile|
total += profile[:controls].length
profile[:controls].each do |_control_name, control|
next unless control[:results]
if control[:results].any? { |r| r[:status] == 'failed' }
failed += 1
elsif control[:results].any? { |r| r[:status] == 'skipped' }
skipped += 1
else
passed += 1
end
end
end
@output_hash[:control_summary] = {
total: total,
failed: failed,
skipped: skipped,
passed: passed,
}
end
private
def profile_info(profile)