mirror of
https://github.com/inspec/inspec
synced 2025-02-17 14:38:43 +00:00
Merge pull request #1109 from chef/ap/show-skip-message
Show skip_message and correct title
This commit is contained in:
commit
9334a4d885
5 changed files with 42 additions and 9 deletions
1
Gemfile
1
Gemfile
|
@ -26,6 +26,7 @@ group :test do
|
||||||
gem 'mocha', '~> 1.1'
|
gem 'mocha', '~> 1.1'
|
||||||
gem 'ruby-progressbar', '~> 1.8'
|
gem 'ruby-progressbar', '~> 1.8'
|
||||||
gem 'inquirer'
|
gem 'inquirer'
|
||||||
|
gem 'nokogiri', '~> 1.6'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :integration do
|
group :integration do
|
||||||
|
|
|
@ -63,10 +63,18 @@ class InspecRspecMiniJson < RSpec::Core::Formatters::JsonFormatter
|
||||||
private
|
private
|
||||||
|
|
||||||
def format_example(example)
|
def format_example(example)
|
||||||
|
if example.metadata[:description_args].length == 0
|
||||||
|
code_description = example.metadata[:full_description]
|
||||||
|
else
|
||||||
|
# For skipped profiles, rspec returns in full_description the skip_message as well. We don't want
|
||||||
|
# to mix the two, so we pick the full_description from the example.metadata[:example_group] hash.
|
||||||
|
code_description = example.metadata[:example_group][:description]
|
||||||
|
end
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
id: example.metadata[:id],
|
id: example.metadata[:id],
|
||||||
status: example.execution_result.status.to_s,
|
status: example.execution_result.status.to_s,
|
||||||
code_desc: example.full_description,
|
code_desc: code_description,
|
||||||
}
|
}
|
||||||
|
|
||||||
unless (pid = example.metadata[:profile_id]).nil?
|
unless (pid = example.metadata[:profile_id]).nil?
|
||||||
|
@ -374,8 +382,6 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
|
||||||
if res.length == 1
|
if res.length == 1
|
||||||
# Single test - be nice and just print the exception message if the test
|
# Single test - be nice and just print the exception message if the test
|
||||||
# failed. No need to say "1 failed".
|
# failed. No need to say "1 failed".
|
||||||
fails.clear
|
|
||||||
skips.clear
|
|
||||||
res[0][:message].to_s
|
res[0][:message].to_s
|
||||||
else
|
else
|
||||||
[
|
[
|
||||||
|
@ -425,7 +431,7 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_tests
|
def print_tests # rubocop:disable Metrics/AbcSize
|
||||||
@anonymous_tests.each do |control|
|
@anonymous_tests.each do |control|
|
||||||
control_result = control[:results]
|
control_result = control[:results]
|
||||||
title = control_result[0][:code_desc].split[0..1].join(' ')
|
title = control_result[0][:code_desc].split[0..1].join(' ')
|
||||||
|
@ -438,7 +444,7 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
|
||||||
test_result = test[:message]
|
test_result = test[:message]
|
||||||
else
|
else
|
||||||
# determine title
|
# determine title
|
||||||
test_result = test[:code_desc].split[2..-1].join(' ')
|
test_result = test[:skip_message] || test[:code_desc].split[2..-1].join(' ')
|
||||||
# show error message
|
# show error message
|
||||||
test_result += "\n" + test[:message] unless test[:message].nil?
|
test_result += "\n" + test[:message] unless test[:message].nil?
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,11 +68,11 @@ Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "Target: local://"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Target: local://"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "working should"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "working should"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "✔ eq \"working\""
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✔ eq \"working\""
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "skippy This"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "skippy\n"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "○ will be skipped intentionally."
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "○ This will be skipped intentionally"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "failing should"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "failing should"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ eq \"as intended\""
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ eq \"as intended\""
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m1 successful\e[0m, \e[31m1 failures\e[0m, \e[37m1 skipped\e[0m"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Test Summary: \e[32m1 successful\e[0m, \e[31m1 failures\e[0m, \e[37m1 skipped\e[0m"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'executes only specified controls' do
|
it 'executes only specified controls' do
|
||||||
|
@ -100,6 +100,18 @@ Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'with a profile that contains skipped controls' do
|
||||||
|
let(:out) { inspec('exec ' + File.join(profile_path, 'skippy-controls') + ' --no-create-lockfile') }
|
||||||
|
let(:json) { JSON.load(out.stdout) }
|
||||||
|
|
||||||
|
it 'exits with an error' do
|
||||||
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "skippy\e[0m\n\e[37m ○ This will be skipped super intentionally.\e[0m\n"
|
||||||
|
out.stdout.force_encoding(Encoding::UTF_8).must_include " ○ CONTROL database: MySQL Session\e[0m\n\e[37m ○ Can't run MySQL SQL checks without authentication\e[0m\n"
|
||||||
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Profile Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m2 skipped\e[0m"
|
||||||
|
out.exit_status.must_equal 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'with a profile that is supported on this version of inspec' do
|
describe 'with a profile that is supported on this version of inspec' do
|
||||||
let(:out) { inspec('exec ' + File.join(profile_path, 'supported_inspec') + ' --no-create-lockfile') }
|
let(:out) { inspec('exec ' + File.join(profile_path, 'supported_inspec') + ' --no-create-lockfile') }
|
||||||
|
|
||||||
|
@ -158,7 +170,7 @@ Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[
|
||||||
|
|
||||||
it 'should print all the results' do
|
it 'should print all the results' do
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ tmp-1.0: Create /tmp directory (1 failed)\e[0m"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ tmp-1.0: Create /tmp directory (1 failed)\e[0m"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory\n"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ undefined method `should_nota'"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ undefined method `should_nota'"
|
||||||
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory\n expected `File /tmp.directory?` to return false, got true\e[0m"
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory\n expected `File /tmp.directory?` to return false, got true\e[0m"
|
||||||
end
|
end
|
||||||
|
|
11
test/unit/mock/profiles/skippy-controls/controls/skipper.rb
Normal file
11
test/unit/mock/profiles/skippy-controls/controls/skipper.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
control 'CONTROL super' do
|
||||||
|
describe 'skippy' do
|
||||||
|
skip 'This will be skipped super intentionally.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
control 'CONTROL database' do
|
||||||
|
describe mysql_session do
|
||||||
|
its('something') { should be 3 }
|
||||||
|
end
|
||||||
|
end
|
3
test/unit/mock/profiles/skippy-controls/inspec.yml
Normal file
3
test/unit/mock/profiles/skippy-controls/inspec.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
name: skippy-controls
|
||||||
|
title: skip skip skip
|
||||||
|
version: 1.0.0
|
Loading…
Add table
Reference in a new issue