#
# FuzzyHash, to_fuzzy_hash, to_html
#
begin
require 'nokogiri'
class RSpec::FuzzyHash < Hash
def == o
return true if super
if o.respond_to? :each
o.each do |k, v|
return false if (self[k.to_sym] || self[k.to_s]) != v
end
return true
end
false
end
end
::Nokogiri::XML::Node.class_eval do
def to_fuzzy_hash
h = RSpec::FuzzyHash.new
attributes.each{|n, v| h[n] = v.value}
h[:content] = content
h
end
end
class String
def to_xhtml css = nil
require 'nokogiri'
node = Nokogiri::HTML(self)
unless css
node
else
nodes = node.css(css)
raise "Elements for '#{css}' CSS query not found!" if nodes.size < 1
raise "Found more than one elment for '#{css}' CSS query!" if nodes.size > 1
nodes.first
end
end
end
rescue LoadError
warn "WARN: some specs require the 'nokogiri' gem, but there's no such gem on this system, these specs will be scipped!"
end