require 'spec_helper' describe "XSLT" do it "transforms an empty html doc into an empty docx doc" do html = '' compare_resulting_wordml_with_expected(html, "\n\n \n \n \n \n \n \n \n \n\n") end it "transforms a div into a docx block element." do html = '
Hello
' compare_resulting_wordml_with_expected(html, " Hello ") end context "transform a span" do it "into a docx block elmenet if child of body." do html = 'Hello' compare_resulting_wordml_with_expected(html, " Hello ") end it "into a docx inline element if not child of body." do html = '
Hello
' compare_resulting_wordml_with_expected(html, " Hello ") end end it "transforms a p into a docx block element." do html = '

Hello

' compare_resulting_wordml_with_expected(html, " Hello ") end protected def compare_resulting_wordml_with_expected(html, resulting_wordml) source = Nokogiri::HTML(html.gsub(/>\s+<")) xslt = Nokogiri::XSLT( File.read(Htmltoword::Document::XSLT_TEMPLATE)) result = xslt.transform(source) if compare_content_of_body?(resulting_wordml) result.at("//w:sectPr").remove result = result.at("//w:body/*") end result.to_s.gsub(/\s+/, " ").should == resulting_wordml.gsub(/\s+/, " ") end def compare_content_of_body?(wordml) wordml !~ /