Make sure we have a proper exit code and report data. (#2747)

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-02-26 16:50:51 -05:00 committed by GitHub
parent 8079bde6eb
commit 62cb6bb846
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View file

@ -129,8 +129,9 @@ module Inspec
end
def run_tests(with = nil)
run_data = @test_collector.run(with)
render_output(run_data)
@run_data = @test_collector.run(with)
# dont output anything if we want a report
render_output(@run_data) unless @conf['report']
@test_collector.exit_code
end

View file

@ -82,6 +82,7 @@ module Inspec
#
# @return [int] exit code
def exit_code
return @rspec_exit_code if @formatter.results.empty?
stats = @formatter.results[:statistics][:controls]
if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0
0

View file

@ -0,0 +1,22 @@
# encoding: utf-8
require 'functional/helper'
describe 'inspec report tests' do
include FunctionalHelper
describe 'report' do
it 'loads a json report' do
o = { 'reporter' => ['json'], 'report' => true }
runner = ::Inspec::Runner.new(o)
runner.add_target(example_profile)
runner.run
runner.report.count.must_equal 4
runner.report.inspect.must_include ':title=>"InSpec Example Profile"'
runner.report.inspect.must_include ':status=>"passed"'
end
# Due to the way we require/use rspec, you can only run one runner.
# You have to reload rspec to run another.
end
end