mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
Merge pull request #404 from chef/sr/report
RspecRunner: re-export report hash
This commit is contained in:
commit
44dc150502
2 changed files with 23 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
|||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
require 'forwardable'
|
||||
require 'uri'
|
||||
require 'inspec/backend'
|
||||
require 'inspec/profile_context'
|
||||
|
@ -13,6 +14,7 @@ require 'inspec/metadata'
|
|||
|
||||
module Inspec
|
||||
class Runner # rubocop:disable Metrics/ClassLength
|
||||
extend Forwardable
|
||||
attr_reader :backend, :rules
|
||||
def initialize(conf = {})
|
||||
@rules = {}
|
||||
|
@ -106,9 +108,8 @@ module Inspec
|
|||
end
|
||||
end
|
||||
|
||||
def run(with = nil)
|
||||
@test_collector.run(with)
|
||||
end
|
||||
def_delegator :@test_collector, :run
|
||||
def_delegator :@test_collector, :report
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -55,6 +55,11 @@ module Inspec
|
|||
with.run_specs(tests)
|
||||
end
|
||||
|
||||
def report
|
||||
reporter = RSpec.configuration.formatters.find { |f| f.is_a? Inspec::RSpecReporter }
|
||||
reporter.output_hash
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Empty the list of registered tests.
|
||||
|
@ -71,6 +76,12 @@ module Inspec
|
|||
# @return [nil]
|
||||
def configure_output
|
||||
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
|
||||
|
||||
setup_reporting if @conf['report']
|
||||
end
|
||||
|
||||
def setup_reporting
|
||||
RSpec.configuration.add_formatter(Inspec::RSpecReporter)
|
||||
end
|
||||
|
||||
# Make sure that all RSpec example groups use the provided ID.
|
||||
|
@ -91,4 +102,12 @@ module Inspec
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RSpecReporter < RSpec::Core::Formatters::JsonFormatter
|
||||
RSpec::Core::Formatters.register Inspec::RSpecReporter
|
||||
|
||||
def initialize(*)
|
||||
super(StringIO.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue