add --format fulljson formatter

This commit is contained in:
Dominik Richter 2016-03-18 02:08:44 +01:00
parent 4c7c79cbf0
commit 040b2eac8e
2 changed files with 31 additions and 4 deletions

View file

@ -3,6 +3,7 @@
# author: Christoph Hartmann
require 'rspec/core'
require 'rspec/core/formatters/json_formatter'
# Extend the basic RSpec JSON Formatter
# to give us an ID in its output
@ -21,10 +22,34 @@ module RSpec::Core::Formatters
run_time: example.execution_result.run_time,
pending_message: example.execution_result.pending_message,
id: example.metadata[:id],
impact: example.metadata[:impact],
title: example.metadata[:title],
desc: example.metadata[:desc],
}
end
end
end
class InspecRspecFormatter < RSpec::Core::Formatters::JsonFormatter
RSpec::Core::Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :close
private
def format_example(example)
res = {
id: example.metadata[:id],
title: example.metadata[:title],
desc: example.metadata[:desc],
code: example.metadata[:code],
impact: example.metadata[:impact],
status: example.execution_result.status.to_s,
code_desc: example.full_description,
ref: example.metadata['file_path'],
ref_line: example.metadata['line_number'],
run_time: example.execution_result.run_time,
start_time: example.execution_result.started_at.to_s,
}
# pending messages are embedded in the resources description
res[:pending] = example.metadata[:description] if res[:status] == 'pending'
res
end
end

View file

@ -81,7 +81,9 @@ module Inspec
RSpec.configuration.output_stream = @conf['output']
end
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
format = @conf['format'] || 'progress'
format = 'InspecRspecFormatter' if format == 'fulljson'
RSpec.configuration.add_formatter(format)
RSpec.configuration.color = @conf['color']
setup_reporting if @conf['report']