mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
175c3e1189
* adding database.xml with attributes to files and mocking it in the helper.rb Signed-off-by: Vern Burton <me@vernburton.com> * adding logic to test class returned by XPATH and using functions from respective classes to fill a array for return, and unit and integration tests to ensure functionality Signed-off-by: Vern Burton <me@vernburton.com> * updating docs to show how attributes are used Signed-off-by: Vern Burton <me@vernburton.com> * 'and' instead of 'or' makes more sense Signed-off-by: Vern Burton <me@vernburton.com> * adding default else for capturing unknown classes from REXML Signed-off-by: Vern Burton <me@vernburton.com> * removing extra newline Signed-off-by: Vern Burton <me@vernburton.com> * adding fail case with enough information to debug in future case Signed-off-by: Vern Burton <me@vernburton.com>
46 lines
1.6 KiB
Ruby
46 lines
1.6 KiB
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
|
|
|
|
describe 'when loading xml with attributes' do
|
|
let (:resource) { load_resource('xml', 'database.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 attribute value through xpath' do
|
|
_(resource.send('//property[@name="url"]/@value')).must_equal ['jdbc:oracle:thin:@databaseserver.domain.tld:1521/DBO.DOMAIN.TLD']
|
|
_(resource.send('/beans/bean[@id="dataSource"]/property[@name="url"]/@value')).must_equal ['jdbc:oracle:thin:@databaseserver.domain.tld:1521/DBO.DOMAIN.TLD']
|
|
end
|
|
end
|
|
end
|