mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
Fix classname in JUnit formatter (#2283)
* Fix classname in JUnit formatter The JUnit formatter currently incorrectly uses `class` instead of `classname` as an attribute. Signed-off-by: Adam Leff <adam@leff.co> * Prefixing classname with profile name, fix functional tests Signed-off-by: Adam Leff <adam@leff.co>
This commit is contained in:
parent
4840eb087e
commit
6875e80bd8
2 changed files with 13 additions and 5 deletions
|
@ -874,8 +874,9 @@ class InspecRspecJUnit < InspecRspecJson
|
|||
private
|
||||
|
||||
def build_profile_xml(profile)
|
||||
profile_name = profile[:name]
|
||||
profile_xml = REXML::Element.new('testsuite')
|
||||
profile_xml.add_attribute('name', profile[:name])
|
||||
profile_xml.add_attribute('name', profile_name)
|
||||
profile_xml.add_attribute('tests', count_profile_tests(profile))
|
||||
profile_xml.add_attribute('failed', count_profile_failed_tests(profile))
|
||||
|
||||
|
@ -883,17 +884,24 @@ class InspecRspecJUnit < InspecRspecJson
|
|||
next if control[:results].nil?
|
||||
|
||||
control[:results].each do |result|
|
||||
profile_xml.add(build_result_xml(control, result))
|
||||
profile_xml.add(build_result_xml(profile_name, control, result))
|
||||
end
|
||||
end
|
||||
|
||||
profile_xml
|
||||
end
|
||||
|
||||
def build_result_xml(control, result)
|
||||
def build_result_xml(profile_name, control, result)
|
||||
result_xml = REXML::Element.new('testcase')
|
||||
result_xml.add_attribute('name', result[:code_desc])
|
||||
result_xml.add_attribute('class', control[:title].nil? ? 'Anonymous' : control[:id])
|
||||
# if there is no control title, we are likely receiving test results from a
|
||||
# "naked" test (a test not located within a control block). Therefore, rather
|
||||
# than outputting the auto-generated ID, i.e.
|
||||
#
|
||||
# "(generated from test_spec.rb:1 de0ce10e4bbbd4d0ff7a65f4234de8c1)")
|
||||
#
|
||||
# ... we'll output "Anonymous" instead.
|
||||
result_xml.add_attribute('classname', control[:title].nil? ? "#{profile_name}.Anonymous" : "#{profile_name}.#{control[:id]}")
|
||||
result_xml.add_attribute('time', result[:run_time])
|
||||
|
||||
if result[:status] == 'failed'
|
||||
|
|
|
@ -51,7 +51,7 @@ describe 'inspec exec with junit formatter' do
|
|||
end
|
||||
|
||||
describe 'the testcase named "gordon_config Can\'t find file ..."' do
|
||||
let(:gordon_yml_tests) { REXML::XPath.match(suite, "//testcase[@class='gordon-1.0' and @name='gordon_config']") }
|
||||
let(:gordon_yml_tests) { REXML::XPath.match(suite, "//testcase[@classname='profile.gordon-1.0' and @name='gordon_config']") }
|
||||
let(:first_gordon_test) {gordon_yml_tests.first}
|
||||
|
||||
it 'should be unique' do
|
||||
|
|
Loading…
Add table
Reference in a new issue