require 'spec_helper'
module Resync
describe XML do
describe '#element' do
it 'returns an element unchanged' do
elem = REXML::Element.new('foo')
expect(XML.element(elem)).to be(elem)
end
it 'returns the root element of a string document' do
xml_str = ''
elem = XML.element(xml_str)
expect(elem).to be_a(REXML::Element)
expect(elem).to be_xml('')
end
it 'returns the root element of a REXML::Document' do
xml_str = ''
doc = REXML::Document.new(xml_str)
elem = XML.element(doc)
expect(elem).to be_a(REXML::Element)
expect(elem).to be_xml(doc.root)
end
it 'parses an XML fragment as an element' do
xml_str = ''
elem = XML.element(xml_str)
expect(elem).to be_a(REXML::Element)
expect(elem).to be_xml(xml_str)
end
it 'parses a file as an XML document' do
file = File.new('spec/data/examples/example-1.xml')
elem = XML.element(file)
expect(elem).to be_a(REXML::Element)
expect(elem.name).to eq('urlset')
end
it 'fails when it gets something other than XML' do
data = 12_345
expect { XML.element(data) }.to raise_exception
end
end
end
end