spec/html2doc_spec.rb in html2doc-0.9.1 vs spec/html2doc_spec.rb in html2doc-0.9.2

- old
+ new

@@ -336,14 +336,27 @@ OUTPUT end it "processes a header with an image" do Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img.html") - expect(guid_clean(File.read("test.doc", encoding: "utf-8"))).to match(%r{Content-Type: image/png}) + doc = guid_clean(File.read("test.doc", encoding: "utf-8")) + expect(doc).to match(%r{Content-Type: image/png}) + expect(doc).to match(%r{file:///C:/Doc/test_files/[^.]+\.png}) end + it "processes a header with an image with absolute path" do + doc = File.read("spec/header_img.html", encoding: "utf-8") + File.open("spec/header_img1.html", "w:UTF-8") do |f| + f.write doc.sub(%r{spec/19160-6.png}, File.expand_path(File.join(File.dirname(__FILE__), "19160-6.png"))) + end + Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img.html") + doc = guid_clean(File.read("test.doc", encoding: "utf-8")) + expect(doc).to match(%r{Content-Type: image/png}) + expect(doc).to match(%r{file:///C:/Doc/test_files/[^.]+\.png}) + end + it "processes a populated document" do simple_body = "<h1>Hello word!</h1> <div>This is a very simple document</div>" Html2Doc.process(html_input(simple_body), filename: "test") expect(guid_clean(File.read("test.doc", encoding: "utf-8"))). @@ -536,9 +549,21 @@ testdoc = File.read("test.doc", encoding: "utf-8") expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT) #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END} #{image_clean(word_body('<img src="https://example.com/19160-6.png"></img>', '<div style="mso-element:footnote-list"/>'))} #{image_clean(WORD_FTR1)} + OUTPUT + end + + it "deals with absolute image locations" do + simple_body = %{<img src="#{File.expand_path(File.dirname(__FILE__))}/19160-6.png">} + Html2Doc.process(html_input(simple_body), filename: "spec/test") + testdoc = File.read("spec/test.doc", encoding: "utf-8") + expect(testdoc).to match(%r{Content-Type: image/png}) + expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT) + #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END} + #{image_clean(word_body('<img src="test_files/cb7b0d19-891e-4634-815a-570d019d454c.png" width="400" height="388"></img>', '<div style="mso-element:footnote-list"/>'))} + #{image_clean(WORD_FTR3)} OUTPUT end it "warns about SVG" do simple_body = '<img src="https://example.com/19160-6.svg">'