Files
Notare/test/test_helper.rb

36 lines
998 B
Ruby

# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "ezdoc"
require "minitest/autorun"
require "tempfile"
require "zip"
module EzdocTestHelpers
# Helper to create a document and return the document.xml content
def create_doc_and_read_xml(&block)
content = nil
Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path, &block)
Zip::File.open(file.path) do |zip|
content = zip.read("word/document.xml").force_encoding("UTF-8")
end
end
content
end
# Helper to create a document and return all XML files
def create_doc_and_read_all_xml(&block)
result = {}
Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path, &block)
Zip::File.open(file.path) do |zip|
zip.each do |entry|
result[entry.name] = zip.read(entry.name).force_encoding("UTF-8") if entry.name.end_with?(".xml")
end
end
end
result
end
end