Sha256: 7754034f5171cdab9078f45304c5c1c9fe032df634da064ed2a0c2cf45a9ce95

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

require 'tmpdir'
require 'fileutils'

describe "EeePub::OCF" do
  before do
    @tmpdir = File.join(Dir.tmpdir, 'eeepub_test')
    FileUtils.mkdir_p(@tmpdir)
    @container = EeePub::OCF::Container.new('foo.opf')
    @ocf = EeePub::OCF.new(:dir => @tmpdir, :container => @container)
  end

  after do
    FileUtils.rm_rf(@tmpdir)
  end

  it 'should return rootfiles' do
    @container.rootfiles.should == [{:full_path => 'foo.opf', :media_type => 'application/oebps-package+xml'}]
  end

  it 'should specify container as String' do
    ocf = EeePub::OCF.new(:dir => @tmpdir, :container => 'foo.opf')
    ocf.container.rootfiles == [{:full_path => 'foo.opf', :media_type => 'application/oebps-package+xml'}]
  end

  it 'should make xml' do
    doc  = Nokogiri::XML(@container.to_xml)
    rootfiles = doc.at('rootfiles')
    rootfiles.should_not be_nil
    rootfiles.search('rootfile').each_with_index do |rootfile, index|
      expect = @container.rootfiles[index]
      rootfile.attribute('full-path').value.should == expect[:full_path]
      rootfile.attribute('media-type').value.should == expect[:media_type]
    end
  end

  it 'should make epub' do
    output_path = File.join('eeepub_test.epub')
    @ocf.save(output_path)
    File.exists?(output_path)
  end

  it 'should stream epub' do
    output = @ocf.render
    expect(output.size).to eq 135
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eeepub_ext-0.8.4 spec/eeepub/ocf_spec.rb