inspec/test/unit/resources/xml_test.rb
Jonathan Morley 3e7d47505c Add support for XML files (#2107)
* Add support for XML files

Signed-off-by: Morley, Jonathan <jmorley@cvent.com>

* Use REXML instead of nokogiri

Signed-off-by: Morley, Jonathan <jmorley@cvent.com>
2017-08-31 09:56:14 +02:00

29 lines
928 B
Ruby

# encoding: utf-8
require 'helper'
require 'inspec/resource'
require 'rexml/document'
describe 'Inspec::Resources::XML' do
describe 'when loading valid XML' do
let (:resource) { load_resource('xml', 'default.xml') }
it 'gets params as a document' do
_(resource.params).must_be_kind_of REXML::Document
end
it 'retrieves empty array if xpath cannot be found' do
_(resource.send('missing')).must_equal []
end
it 'retrieves xpath by name' do
_(resource.send('breakfast_menu/food[1]/name')).must_equal ['Belgian Waffles']
_(resource.send('/breakfast_menu/food[1]/name')).must_equal ['Belgian Waffles']
end
it 'retrieves many xpaths by name' do
_(resource.send('/breakfast_menu/food/name')).must_equal ['Belgian Waffles', 'Strawberry Belgian Waffles']
_(resource.send('//name')).must_equal ['Belgian Waffles', 'Strawberry Belgian Waffles']
end
end
end