DEV: Apply syntax_tree formatting to spec/*

This commit is contained in:
David Taylor
2023-01-09 11:18:21 +00:00
parent 0cf6421716
commit cb932d6ee1
907 changed files with 58693 additions and 45909 deletions

View File

@ -1,10 +1,8 @@
# frozen_string_literal: true
require 'nokogiri/xml/parse_options'
require "nokogiri/xml/parse_options"
RSpec::Matchers.define :match_html do |expected|
match do |actual|
make_canonical_html(expected).eql? make_canonical_html(actual)
end
match { |actual| make_canonical_html(expected).eql? make_canonical_html(actual) }
failure_message do |actual|
"after sanitizing for extra white space and compactness, expected:\n#{actual}\n to match:\n#{expected}"
@ -15,17 +13,16 @@ RSpec::Matchers.define :match_html do |expected|
end
def make_canonical_html(html)
doc = Nokogiri::HTML5(html) do |config|
config[:options] = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::COMPACT
end
doc =
Nokogiri.HTML5(html) do |config|
config[:options] = Nokogiri::XML::ParseOptions::NOBLANKS |
Nokogiri::XML::ParseOptions::COMPACT
end
doc.traverse do |node|
if node.node_name&.downcase == "text"
node.content = node.content.gsub(/\s+/, ' ').strip
end
node.content = node.content.gsub(/\s+/, " ").strip if node.node_name&.downcase == "text"
end
doc.to_html
end
end