Merge pull request #404 from chef/sr/report

RspecRunner: re-export report hash
This commit is contained in:
Christoph Hartmann 2016-02-03 14:33:45 +01:00
commit 44dc150502
2 changed files with 23 additions and 3 deletions

View file

@ -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

View file

@ -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