require 'spec_helper' module GutenbergRdf describe Rdf do let(:xml) do ' 2006-09-28 en Project Gutenberg Public domain in the USA. ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects an id" do expect(rdf.id).to eql "98765" end it "expects a published date" do expect(rdf.published).to eql "2006-09-28" end it "expects a publisher" do expect(rdf.publisher).to eql "Project Gutenberg" end it "expects a language" do expect(rdf.language).to eql "en" end it "expects the rights" do expect(rdf.rights).to eql "Public domain in the USA." end describe "#type" do let(:xml) do ' Text ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expect the type of entity" do expect(rdf.type).to eql 'Text' end end describe "Titles" do let(:xml) do ' A Great Title ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects a title" do expect(rdf.title).to eql 'A Great Title' end it "expects subtitle to be empty" do expect(rdf.subtitle).to eql '' end context "with a title and subtitle, on separate lines" do let(:xml) do ' A Great Multi-Title Or, a Subtitle ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects the title to be the first line" do expect(rdf.title).to eql 'A Great Multi-Title' end it "expects the subtitle to be the second line" do expect(rdf.subtitle).to eql 'Or, a Subtitle' end end context "with; title, or, subtitle (we need to split on the 'or')" do let(:xml) do ' A Great Multi-Title, or, a Subtitle ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects the title to be the first line" do expect(rdf.title).to eql 'A Great Multi-Title' end it "expects the subtitle to be the second line" do expect(rdf.subtitle).to eql 'a Subtitle' end end context "when title:subtitle are separated by a colon" do let(:xml) do ' A Great Multi-Title: And a Subtitle ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects a title" do expect(rdf.title).to eql 'A Great Multi-Title' end it "expects a subtitle" do expect(rdf.subtitle).to eql 'And a Subtitle' end end context "when title; and subtitle are separated by a semi-colon" do let(:xml) do ' A Great Multi-Title; Or, a Subtitle ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects a title" do expect(rdf.title).to eql 'A Great Multi-Title' end it "expects a subtitle" do expect(rdf.subtitle).to eql 'Or, a Subtitle' end context "...except when subtitles already exists" do let(:xml) do ' A Great Multi-Title; and some other text Then a Subtitle on a newline ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects a title" do expect(rdf.title).to eql 'A Great Multi-Title; and some other text' end it "expects a subtitle" do expect(rdf.subtitle).to eql 'Then a Subtitle on a newline' end end end end describe "#authors" do let(:xml) do ' 1830 1905 Dodge, Mary Mapes Dodge, Mary Verschillende Various ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "returns the correct number of authors" do expect(rdf.authors.count).to be 2 end it "expects an author object" do expect(rdf.authors.first.class).to be Rdf::Agent end it "has the correct author names" do expect(rdf.authors.first.fullname).to eq 'Mary Mapes Dodge' end it "expects the author to have an aut role" do expect(rdf.authors.last.role).to eq 'aut' end it "expects other agents to have the correct role" do expect(rdf.authors.first.role).to eq 'ctb' end end describe "#subjects" do let(:xml) do %q{ Children's literature -- Periodicals Children's periodicals, American PZ } end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects correct number to be returned" do expect(rdf.subjects.count).to be 2 end it "expects the correct data" do expect(rdf.subjects.first).to eql "Children's literature -- Periodicals" expect(rdf.subjects.last).to eql "Children's periodicals, American" end end describe "#covers" do describe "official PG covers" do let(:xml) do ' http://www.gutenberg.org/files/12345/12345-h/images/cover.jpg 92652 application/epub+zip 2013-09-21T19:22:32.115259 10856 image/jpeg 2013-09-21T19:22:34.484114 1904 image/jpeg 2013-09-21T19:22:34.379124 ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects the correct number of entries returned" do expect(rdf.covers.count).to be 3 end it "expects those to be used" do expect(rdf.covers[0]).to eql 'http://www.gutenberg.org/ebooks/12345.cover.medium' expect(rdf.covers[1]).to eql 'http://www.gutenberg.org/ebooks/12345.cover.small' end it "expects any other images to be listed after the official ones" do expect(rdf.covers[2]).to eql 'http://www.gutenberg.org/files/12345/12345-h/images/cover.jpg' end end describe "HTML ebook cover image" do let(:xml) do ' file:///public/vhost/g/gutenberg/html/files/12345/12345-rst/images/cover.jpg file:///public/vhost/g/gutenberg/html/files/12345/12345-h/images/cover.jpg http://www.gutenberg.org/files/12345/12345-h/images/cover.jpg ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects only unique entries" do expect(rdf.covers.count).to be 2 end it "should convert File URIs to the Gutenberg URL" do expect(rdf.covers.first).to match 'http://www.gutenberg.org' end it "expects the covers to be listed in the correct order" do expect(rdf.covers[0]).to eql 'http://www.gutenberg.org/files/12345/12345-h/images/cover.jpg' expect(rdf.covers[1]).to eql 'http://www.gutenberg.org/files/12345/12345-rst/images/cover.jpg' end end end describe "#ebook" do let(:xml) do ' 293684 text/plain; charset=utf-8 2010-02-16T08:29:52.373092 116685 application/zip text/plain; charset=us-ascii 2006-09-28T12:37:26 ' end let(:rdf) { Rdf.new(REXML::Document.new(xml)) } it "expects the correct number of entries" do expect(rdf.ebooks.count).to be 2 end it "expects an entry to be a Media class" do expect(rdf.ebooks.first.class).to be Rdf::Media end end end end