mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
Update junit tests to use nokogiri
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
064d3f5d1c
commit
955ab36922
2 changed files with 17 additions and 18 deletions
1
Gemfile
1
Gemfile
|
@ -25,6 +25,7 @@ group :test do
|
||||||
gem "rake", ">= 10"
|
gem "rake", ">= 10"
|
||||||
gem "simplecov", ["~> 0.10", "<=0.18.2"]
|
gem "simplecov", ["~> 0.10", "<=0.18.2"]
|
||||||
gem "concurrent-ruby", "~> 1.0"
|
gem "concurrent-ruby", "~> 1.0"
|
||||||
|
gem "nokogiri", "~> 1.9"
|
||||||
gem "mocha", "~> 1.1"
|
gem "mocha", "~> 1.1"
|
||||||
gem "ruby-progressbar", "~> 1.8"
|
gem "ruby-progressbar", "~> 1.8"
|
||||||
gem "webmock", "~> 3.0"
|
gem "webmock", "~> 3.0"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require "functional/helper"
|
require "functional/helper"
|
||||||
require "rexml/document"
|
require "nokogiri"
|
||||||
|
|
||||||
describe "inspec exec with junit formatter" do
|
describe "inspec exec with junit formatter" do
|
||||||
include FunctionalHelper
|
include FunctionalHelper
|
||||||
|
@ -9,11 +9,10 @@ describe "inspec exec with junit formatter" do
|
||||||
it "can execute a simple file with the junit formatter" do
|
it "can execute a simple file with the junit formatter" do
|
||||||
out = inspec("exec " + example_control + " --reporter junit --no-create-lockfile")
|
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 ""
|
_(out.stderr).must_equal ""
|
||||||
|
doc = Nokogiri::XML(out.stdout)
|
||||||
|
_(doc.document?).must_equal true
|
||||||
|
_(doc.errors).must_be_empty
|
||||||
|
|
||||||
assert_exit_code 0, out
|
assert_exit_code 0, out
|
||||||
end
|
end
|
||||||
|
@ -21,44 +20,43 @@ describe "inspec exec with junit formatter" do
|
||||||
it "can execute the profile with the junit formatter" do
|
it "can execute the profile with the junit formatter" do
|
||||||
out = inspec("exec " + complete_profile + " --reporter junit --no-create-lockfile")
|
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 ""
|
_(out.stderr).must_equal ""
|
||||||
|
doc = Nokogiri::XML(out.stdout)
|
||||||
|
_(doc.document?).must_equal true
|
||||||
|
_(doc.errors).must_be_empty
|
||||||
|
|
||||||
assert_exit_code 0, out
|
assert_exit_code 0, out
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "execute a profile with junit formatting" do
|
describe "execute a profile with junit formatting" do
|
||||||
let(:doc) { REXML::Document.new(inspec("exec " + example_profile + " --reporter junit --no-create-lockfile").stdout) }
|
let(:doc) { Nokogiri::XML(inspec("exec " + example_profile + " --reporter junit --no-create-lockfile").stdout) }
|
||||||
|
|
||||||
describe "the document" do
|
describe "the document" do
|
||||||
it "has only one testsuite" do
|
it "has only one testsuite" do
|
||||||
_(doc.elements.to_a("//testsuite").length).must_equal 1
|
_(doc.xpath("//testsuite").length).must_equal 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe "the test suite" do
|
describe "the test suite" do
|
||||||
let(:suite) { doc.elements.to_a("//testsuites/testsuite").first }
|
let(:suite) { doc.xpath("//testsuites/testsuite").first }
|
||||||
|
|
||||||
it "must have 4 testcase children" do
|
it "must have 4 testcase children" do
|
||||||
_(suite.elements.to_a("//testcase").length).must_equal 4
|
_(suite.xpath("//testcase").length).must_equal 4
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has the tests attribute with 4 total tests" do
|
it "has the tests attribute with 4 total tests" do
|
||||||
_(suite.attribute("tests").value).must_equal "4"
|
_(suite.attr("tests")).must_equal "4"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has the failures attribute with 0 total tests" do
|
it "has the failures attribute with 0 total tests" do
|
||||||
_(suite.attribute("failed").value).must_equal "0"
|
_(suite.attr("failed")).must_equal "0"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has 2 elements named "File / should be directory"' do
|
it 'has 3 elements named "File / should be directory"' do
|
||||||
_(REXML::XPath.match(suite, "//testcase[@name='File / is expected to be directory']").length).must_equal 3
|
_(suite.xpath("//testcase[@name='File / is expected to be directory']").length).must_equal 3
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'the testcase named "example_config Can\'t find file ..."' do
|
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(:example_yml_tests) { suite.xpath("//testcase[@classname='profile.example-1.0' and @name='example_config']") }
|
||||||
let(:first_example_test) { example_yml_tests.first }
|
let(:first_example_test) { example_yml_tests.first }
|
||||||
|
|
||||||
it "should be unique" do
|
it "should be unique" do
|
||||||
|
|
Loading…
Reference in a new issue