2
0
Fork 0
mirror of https://github.com/inspec/inspec synced 2025-03-07 08:47:29 +00:00
inspec/test/functional/inspec_exec_junit_test.rb
Miah Johnson 4f642e0942 Clean up schema PR.
Signed-off-by: Miah Johnson <miah@chia-pet.org>
2020-02-05 17:06:55 -08:00

82 lines
2.5 KiB
Ruby

require "functional/helper"
require "rexml/document"
describe "inspec exec with junit formatter" do
include FunctionalHelper
parallelize_me!
it "can execute a simple file with the junit formatter" do
out = inspec("exec " + example_control + " --reporter junit --no-create-lockfile")
# TODO: rexml is about as slow as you can go. Use nokogiri
doc = REXML::Document.new(out.stdout)
_(doc.has_elements?).must_equal true
_(out.stderr).must_equal ""
skip_windows!
assert_exit_code 0, out
end
it "can execute the profile with the junit formatter" do
out = inspec("exec " + complete_profile + " --reporter junit --no-create-lockfile")
# TODO: _never_ use rexml. Anything else is guaranteed faster
doc = REXML::Document.new(out.stdout)
_(doc.has_elements?).must_equal true
_(out.stderr).must_equal ""
assert_exit_code 0, out
end
describe "execute a profile with junit formatting" do
let(:doc) { REXML::Document.new(inspec("exec " + example_profile + " --reporter junit --no-create-lockfile").stdout) }
describe "the document" do
it "has only one testsuite" do
_(doc.elements.to_a("//testsuite").length).must_equal 1
end
end
describe "the test suite" do
let(:suite) { doc.elements.to_a("//testsuites/testsuite").first }
it "must have 6 testcase children" do
_(suite.elements.to_a("//testcase").length).must_equal 4
end
it "has the tests attribute with 5 total tests" do
_(suite.attribute("tests").value).must_equal "4"
end
it "has the failures attribute with 0 total tests" do
skip_windows!
_(suite.attribute("failed").value).must_equal "0"
end
it 'has 2 elements named "File / should be directory"' do
_(REXML::XPath.match(suite, "//testcase[@name='File / is expected to be directory']").length).must_equal 3
end
describe 'the testcase named "example_config Can\'t find file ..."' do
let(:example_yml_tests) { REXML::XPath.match(suite, "//testcase[@classname='profile.example-1.0' and @name='example_config']") }
let(:first_example_test) { example_yml_tests.first }
it "should be unique" do
skip
_(example_yml_tests.length).must_equal 1
end
it "should be skipped" do
skip
if is_windows?
_(first_example_test.elements.to_a("//skipped").length).must_equal 2
else
_(first_example_test.elements.to_a("//skipped").length).must_equal 1
end
end
end
end
end
end