Update to safe navigation exit code skip search. (#3541)

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-10-24 15:08:07 -04:00 committed by GitHub
parent 955d444b95
commit d40dc7c41f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -84,7 +84,7 @@ module Inspec
def exit_code
return @rspec_exit_code if @formatter.results.empty?
stats = @formatter.results[:statistics][:controls]
skipped = @formatter.results[:profiles].first[:status] == 'skipped'
skipped = @formatter.results&.fetch(:profiles, nil)&.first&.fetch(:status, nil) == 'skipped'
if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0 && !skipped
0
elsif stats[:failed][:total] > 0

View file

@ -36,6 +36,12 @@ describe Inspec::Runner do
end
end
describe 'testing runner.run exit codes' do
it 'returns proper exit code when no profile is added' do
runner.run.must_equal 0
end
end
describe 'when backend caching is enabled' do
it 'returns a backend with caching' do
opts = { command_runner: :generic, backend_cache: true }