require 'spec_helper' module Resync describe XMLParser do describe '#parse' do it 'parses an XML document' do data = File.read('spec/data/examples/example-1.xml') doc = REXML::Document.new(data) urlset = XMLParser.parse(doc) expect(urlset).to be_a(ResourceList) end it 'parses a urlset' do data = File.read('spec/data/examples/example-1.xml') root = REXML::Document.new(data).root urlset = XMLParser.parse(root) expect(urlset).to be_a(ResourceList) end it 'parses a sitemapindex' do data = File.read('spec/data/examples/example-8.xml') root = REXML::Document.new(data).root sitemapindex = XMLParser.parse(root) expect(sitemapindex).to be_a(ResourceListIndex) end it 'parses a String' do data = File.read('spec/data/examples/example-1.xml') urlset = XMLParser.parse(data) expect(urlset).to be_a(ResourceList) end it 'parses a file' do file = File.new('spec/data/examples/example-1.xml') urlset = XMLParser.parse(file) expect(urlset).to be_a(ResourceList) end it 'parses an XML fragment' do data = ' http://example.com/res1 ' urlset = XMLParser.parse(data) expect(urlset).to be_a(ResourceList) end it 'fails if the root element has no metadata' do data = ' http://example.com/res1 ' expect { XMLParser.parse(data) }.to raise_error(ArgumentError) end it 'fails if the root element\'s metadata has no capability attribute' do data = ' http://example.com/res1 ' expect { XMLParser.parse(data) }.to raise_error(ArgumentError) end it 'fails if the root element\'s metadata has an unknown capability attribute' do data = ' http://example.com/res1 ' expect { XMLParser.parse(data) }.to raise_error(ArgumentError) end it 'fails when it gets something other than a or ' do data = 'http://example.com/resourcelist-part1.xml' expect { XMLParser.parse(data) }.to raise_error(ArgumentError) end it 'fails when it gets something other than XML' do data = 12_345 expect { XMLParser.parse(data) }.to raise_error(ArgumentError) end end end end