# encoding: UTF-8 require 'spec_helper' module Roadie describe MarkupImprover do def improve(html) dom = Nokogiri::HTML.parse html MarkupImprover.new(dom, html).improve dom end # JRuby up to at least 1.6.0 has a bug where the doctype of a document cannot be changed. # See https://github.com/sparklemotion/nokogiri/issues/984 def pending_for_buggy_jruby # No reason to check for version yet since no existing version has a fix. skip "Pending until Nokogiri issue #984 is fixed and released" if defined?(JRuby) end describe "automatic doctype" do it "inserts a HTML5 doctype if no doctype is present" do pending_for_buggy_jruby expect(improve("").internal_subset.to_xml).to eq("") end it "does not insert duplicate doctypes" do html = improve('
').to_html expect(html.scan('DOCTYPE').size).to eq(1) end it "leaves other doctypes alone" do dtd = "" html = "#{dtd}" expect(improve(html).internal_subset.to_xml.strip).to eq(dtd) end end describe "basic HTML structure" do it "inserts a element as the root" do expect(improve("")).to have_selector("html") expect(improve("