ruby-avm-library/spec/avm/xmp_spec.rb

75 lines
2.5 KiB
Ruby
Raw Normal View History

2011-03-10 22:45:21 +00:00
require 'spec_helper'
require 'avm/xmp'
describe AVM::XMP do
let(:xmp) { self.class.describes.new }
2011-03-11 18:27:17 +00:00
subject { xmp }
describe '#get_refs' do
2011-03-10 22:45:21 +00:00
before {
2011-03-11 18:27:17 +00:00
xmp.get_refs do |refs|
2011-03-10 22:45:21 +00:00
refs[:dublin_core] << "<rdf:addedToDublinCore />"
refs[:iptc] << "<rdf:addedToIPTC />"
2011-03-14 16:35:29 +00:00
refs[:photoshop] << '<rdf:addedToPhotoshop />'
2011-03-15 14:55:09 +00:00
refs[:avm] << '<rdf:addedToAVM />'
2011-03-10 22:45:21 +00:00
end
}
2011-03-14 16:35:29 +00:00
it "should have gotten the refs correctly" do
2011-03-15 14:55:09 +00:00
xmp.doc.at_xpath('//rdf:Description[@rdf:about="Dublin Core"]//rdf:addedToDublinCore').should_not be_nil
xmp.doc.at_xpath('//rdf:Description[@rdf:about="IPTC"]//rdf:addedToIPTC').should_not be_nil
xmp.doc.at_xpath('//rdf:Description[@rdf:about="Photoshop"]//rdf:addedToPhotoshop').should_not be_nil
xmp.doc.at_xpath('//rdf:Description[@rdf:about="AVM"]//rdf:addedToAVM').should_not be_nil
2011-03-14 16:35:29 +00:00
end
2011-03-10 22:45:21 +00:00
end
2011-03-11 18:27:17 +00:00
describe '.from_string' do
let(:xmp) { self.class.describes.from_string(string) }
2011-03-15 14:55:09 +00:00
let(:string) { '<xml xmlns:rdf="cats"><rdf:RDF><node /></rdf:RDF></xml>' }
2011-03-11 18:27:17 +00:00
specify { xmp.doc.at_xpath('//node').should_not be_nil }
end
describe '#ensure_descriptions_findable!' do
let(:document) { <<-XML }
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
#{content}
</rdf:RDF>
</x:xmpmeta>
XML
let(:xmp) { self.class.describes.new(Nokogiri::XML(document)) }
context 'no nodes within' do
let(:content) { '' }
2011-03-15 14:55:09 +00:00
[ 'Dublin Core', 'IPTC', 'Photoshop', 'AVM' ].each do |which|
specify { xmp.doc.at_xpath(%{//rdf:Description[@rdf:about="#{which}"]}).children.should be_empty }
2011-03-11 18:27:17 +00:00
end
end
context 'has identifying nodes within' do
let(:content) { <<-XML }
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:creator />
</rdf:Description>
<rdf:Description rdf:about="" xmlns:Iptc4xmpCore="http://itpc.org/stf/Iptc4xmpCore/1.0/xmlns/">
<Iptc4xmpCore:CreatorContactInfo rdf:parseType="Resource" />
2011-03-15 14:55:09 +00:00
</rdf:Description>
<rdf:Description rdf:about="" xmlns:Photoshop="http://ns.adobe.com/photoshop/1.0/">
<photoshop:Something />
</rdf:Description>
<rdf:Description rdf:about="" xmlns:avm="http://www.communicatingastronomy.org/avm/1.0/">
<avm:Something />
2011-03-11 18:27:17 +00:00
</rdf:Description>
XML
2011-03-15 14:55:09 +00:00
[ 'Dublin Core', 'IPTC', 'Photoshop', 'AVM' ].each do |which|
specify { xmp.doc.at_xpath(%{//rdf:Description[@rdf:about="#{which}"]}).should_not be_nil }
2011-03-11 18:27:17 +00:00
end
end
end
2011-03-10 22:45:21 +00:00
end