Helpers for asserting on generated documents.
Comparing two .docx files byte for byte is not useful: the archives differ
in timestamps and compression, and equivalent XML can be written in several
ways. These helpers compare the parts of a package instead, canonicalising
the XML ones first.
import Sablon.Test.Assertions
test "renders the invoice" do
Sablon.render_to_file(template, "tmp/invoice.docx", context)
assert_docx_equal("test/fixtures/invoice_sample.docx", "tmp/invoice.docx")
end
Summary
Functions
Raises unless the two .docx files hold the same content.
Rewrites XML into a canonical form: indentation between elements is dropped, attributes are sorted by name, line endings are normalised and the prolog is ignored. What remains is what Word actually sees.
Returns the names of the parts that differ between two .docx files, along
with the canonical form of each side.
Functions
Raises unless the two .docx files hold the same content.
The failure message names every part that differs, so it is clear whether a change is in the body, a header or the relationships.
@spec canonicalize(binary() | Sablon.XML.Document.t() | Sablon.XML.Node.t()) :: binary()
Rewrites XML into a canonical form: indentation between elements is dropped, attributes are sorted by name, line endings are normalised and the prolog is ignored. What remains is what Word actually sees.
Returns the names of the parts that differ between two .docx files, along
with the canonical form of each side.
Only XML parts are compared textually; other parts, images for instance, are compared byte for byte.