require 'spec_helper' describe Softcover::Builders::Epub do before(:all) do generate_book @file_to_be_removed = path('html/should_be_removed.html') File.write(@file_to_be_removed, '') silence { `softcover build:epub` } @builder = Softcover::Builders::Epub.new @builder.build! end after(:all) { remove_book } subject(:builder) { @builder } it "should be valid" do output = `softcover epub:validate` expect(output).to match(/No errors or warnings/) end describe "mimetype file" do it "should exist in the right directory" do expect(path('epub/mimetype')).to exist end it "should have the right contents" do File.open('epub/mimetype') do |f| expect(f.read).to match(/application\/epub\+zip/) end end end describe "META-INF" do it "should have the right container file" do expect('epub/META-INF/container.xml').to exist end it "should have the right contents" do File.open('epub/META-INF/container.xml') do |f| expect(f.read).to match(/rootfile full-path="OEBPS\/content.opf"/) end end end describe "OEBPS" do describe "contents" do describe "opf file" do let(:content_opf) { 'epub/OEBPS/content.opf' } let(:doc) { Nokogiri.XML(File.read(content_opf)) } subject { content_opf } it { should exist } it "should have the chapter right items" do expect(doc.css('item#a_chapter')).not_to be_empty expect(doc.css('item#another_chapter')).not_to be_empty end it "should have the right TOC chapter refs" do toc_refs = doc.css('itemref').map { |node| node['idref'] } expect(toc_refs).to eq %w[cover frontmatter a_chapter another_chapter yet_another_chapter] end it "should have the right title" do expect(doc.to_xml).to match(/>#{builder.manifest.title}#{author}#{copyright} #{author}#{builder.manifest.title}