Skip to content

Commit

Permalink
Merge pull request #1896 from chef/dr/dupe-message
Browse files Browse the repository at this point in the history
remove duplicate message in describe.one blocks
  • Loading branch information
adamleff authored Jun 7, 2017
2 parents 1c55d12 + d051c8b commit 0d61401
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/inspec/rspec_json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def stop(notification)
format_example(example).tap do |hash|
e = example.exception
next unless e
hash[:message] = e.message
hash[:message] = exception_message(e)

next if e.is_a? RSpec::Expectations::ExpectationNotMetError
hash[:exception] = e.class.name
Expand All @@ -63,6 +63,14 @@ def stop(notification)

private

def exception_message(exception)
if exception.is_a?(RSpec::Core::MultipleExceptionError)
exception.all_exceptions.map(&:message).uniq.join("\n\n")
else
exception.message
end
end

def format_example(example)
if !example.metadata[:description_args].empty? && example.metadata[:skip]
# For skipped profiles, rspec returns in full_description the skip_message as well. We don't want
Expand Down
8 changes: 8 additions & 0 deletions test/functional/inspec_exec_jsonmin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
JSON::Schema.validate(data, schema)
end

it 'does not contain any dupilcate results with describe.one' do
out = inspec("shell -c 'describe.one do describe 1 do it { should cmp 2 } end end' --format=json-min")
out.stderr.must_equal ''
data = JSON.parse(out.stdout)
data['controls'].length.must_equal 1
data['controls'][0]['message'].must_equal "\nexpected: 2\n got: 1\n\n(compared using `cmp` matcher)\n"
end

describe 'execute a profile with mini json formatting' do
let(:json) { JSON.load(inspec('exec ' + example_profile + ' --format json-min --no-create-lockfile').stdout) }
let(:controls) { json['controls'] }
Expand Down

0 comments on commit 0d61401

Please sign in to comment.