require 'test_helper'
require 'epubmaker'
require 'epubmaker/zip_exporter'
require 'fileutils'
class ZipExporterTest < Test::Unit::TestCase
include EPUBMaker
def setup
@tmpdir = Dir.mktmpdir
@epubdir = "#{@tmpdir}/epubdir"
FileUtils.mkdir_p("#{@epubdir}/META-INF")
FileUtils.mkdir_p("#{@epubdir}/OEBPS")
File.write("#{@epubdir}/mimetype", 'application/epub+zip')
container_xml = <<-EOB
hello, world!
EOB File.write("#{@epubdir}/META-INF/container.xml", container_xml) File.write("#{@epubdir}/OEBPS/book.opf", book_opf) File.write("#{@epubdir}/OEBPS/ch1.xhtml", ch1_xhtml) end def test_export_zipcmd if Gem.win_platform? ## skip this test return end config = { 'epubmaker' => {} } epubfile = File.join(@tmpdir, 'test.epub') exporter = ZipExporter.new(@epubdir, config) exporter.export_zip_extcmd(epubfile) assert_true(File.exist?(epubfile)) if defined?(Zip) File.open(epubfile) do |f| ::Zip::InputStream.open(f) do |fzip| ## get first entry entry = fzip.get_next_entry assert_equal 'mimetype', entry.name assert_equal 'application/epub+zip', fzip.read end end end end def test_export_rubyzip return unless defined?(Zip) ## skip test config = { 'epubmaker' => {} } epubfile = File.join(@tmpdir, 'test.epub') exporter = ZipExporter.new(@epubdir, config) exporter.export_zip_rubyzip(epubfile) assert_true(File.exist?(epubfile)) File.open(epubfile) do |f| ::Zip::InputStream.open(f) do |fzip| ## get first entry entry = fzip.get_next_entry assert_equal 'mimetype', entry.name assert_equal 'application/epub+zip', fzip.read end end end def teardown FileUtils.remove_entry_secure(@tmpdir) end end