Sha256: de87397a4c869f7612dbce75b4e991e175b4574a2fdb574f60ff86d41b64578a
Contents?: true
Size: 1.53 KB
Versions: 5
Compression:
Stored size: 1.53 KB
Contents
require_relative 'helper' require 'epub/maker' require 'epzip' class TestImplaceEditing < Test::Unit::TestCase def setup @assets_dir = Pathname(__dir__)/'fixtures'/'book' @dir = Pathname.mktmpdir('epub-maker-test') @file = @dir/'book.epub' Epzip.zip @assets_dir.to_s, @file.to_path @book = EPUB::Parser.parse(@file) end def teardown (@assets_dir/'mimetype').rmtree @dir.remove_entry_secure if @dir.exist? end def test_save_parsed_book nav = @book.nav doc = nav.content_document.nokogiri title = doc.search('title').first title.content = 'Edited Title' nav.content = doc.to_xml nav.save assert_match '<title>Edited Title</title>', nav.read end def test_edit item = @book.resources.find(&:xhtml?) item.edit do doc = Nokogiri.XML(item.read) title = doc.search('title').first title.content = 'Edited Title' item.content = doc.to_xml end assert_match '<title>Edited Title</title>', item.read end def test_edit_with_rexml require 'rexml/quickpath' item = @book.resources.find(&:xhtml?) item.edit_with_rexml do |doc| title = REXML::QuickPath.first(doc, '//title') title.text = 'Edited Title' end assert_match '<title>Edited Title</title>', item.read end def test_edit_with_nokogiri item = @book.resources.find(&:xhtml?) item.edit_with_nokogiri do |doc| title = doc.search('title').first title.content = 'Edited Title' end assert_match '<title>Edited Title</title>', item.read end end
Version data entries
5 entries across 5 versions & 1 rubygems