From 47c6427082d5622b77bb0769229cd8fab9dec62c Mon Sep 17 00:00:00 2001 From: Victoria Jeffrey Date: Mon, 26 Sep 2016 12:10:43 -0400 Subject: [PATCH] print profile info before test results (inherited profiles) --- lib/inspec/rspec_json_formatter.rb | 39 ++++++++++++++++++----------- test/functional/inspec_exec_test.rb | 8 ++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/inspec/rspec_json_formatter.rb b/lib/inspec/rspec_json_formatter.rb index 5a85489e9..896f8eec1 100644 --- a/lib/inspec/rspec_json_formatter.rb +++ b/lib/inspec/rspec_json_formatter.rb @@ -287,6 +287,7 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength @missing_controls = [] @anonymous_tests = [] @control_tests = [] + @profile_printed = false super(*args) end @@ -296,17 +297,7 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength print_tests output.puts('') - @profiles_info.each do |profile| - next if profile[:already_printed] - @current_profile = profile - next unless print_current_profile - print_line( - color: '', indicator: @indicators['empty'], id: '', profile: '', - summary: 'No tests executed.' - ) if @current_control.nil? - output.puts('') - end - + print_profiles_info if !@profile_printed controls_res = controls_summary tests_res = tests_summary @@ -463,9 +454,8 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength def flush_current_control return if @current_control.nil? - prev_profile = @current_profile @current_profile = @profiles_info.find { |i| i[:id] == @current_control[:profile_id] } - print_current_profile if prev_profile != @current_profile + print_current_profile if !@profile_printed fails, skips, passes, summary_indicator = current_control_infos summary = current_control_summary(fails, skips) @@ -495,14 +485,32 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength output.puts(before + connection.uri + after) end + def print_profiles_info + @profiles_info.each do |profile| + next if profile[:already_printed] + @current_profile = profile + next unless print_current_profile + print_line( + color: '', indicator: @indicators['empty'], id: '', profile: '', + summary: 'No tests executed.' + ) if @current_control.nil? + output.puts('') + end + end + def print_current_profile profile = @current_profile - return false if profile.nil? - + if profile.nil? + print_profiles_info + @profile_printed = true + return true + end output.puts '' profile[:already_printed] = true + if profile[:name].nil? print_target('Target: ', "\n\n") + @profile_printed = true return true end @@ -515,6 +523,7 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength output.puts 'Version: ' + (profile[:version] || 'unknown') print_target('Target: ', "\n") output.puts + @profile_printed = true true end diff --git a/test/functional/inspec_exec_test.rb b/test/functional/inspec_exec_test.rb index 5d0118c2f..4c3f36148 100644 --- a/test/functional/inspec_exec_test.rb +++ b/test/functional/inspec_exec_test.rb @@ -188,6 +188,14 @@ Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[ end end + describe 'given an inherited profile' do + let(:out) { inspec('exec ' + simple_inheritance) } + + it 'should print the profile information and then the test results' do + out.stdout.force_encoding(Encoding::UTF_8).must_include "local://\n\n\n\e[31;1m ✖ tmp-1.0: Create /tmp directory (1 failed)\e[0m\n\e[31;1m ✖ File /tmp should not be directory\n" + end + end + describe 'using namespaced resources' do it 'works' do out = inspec('exec ' + File.join(profile_path, 'dependencies', 'resource-namespace') + ' --no-create-lockfile')