$:.push(File.join(File.dirname(__FILE__),'..','lib'))
require 'nokogiri'
require 'equivalent-xml'
describe EquivalentXml do
it "should consider a document equivalent to itself" do
doc1 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc1).should == true
end
it "should ensure that attributes match" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc2).should == false
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc2).should == true
end
it "shouldn't care about attribute order" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc2).should == true
end
it "shouldn't care about element order by default" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("thingsfoo bar baz")
EquivalentXml.equivalent?(doc1,doc2).should == true
end
it "should care about element order if :element_order => true is specified" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("thingsfoo bar baz")
EquivalentXml.equivalent?(doc1,doc2,:element_order => true).should == false
end
it "should ensure nodesets have the same number of elements" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("thingsfoo bar baz")
EquivalentXml.equivalent?(doc1,doc2).should == false
end
it "should ensure namespaces match" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc2).should == false
end
it "should normalize simple whitespace by default" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc2).should == true
end
it "shouldn't normalize simple whitespace if :normalize_whitespace => false is specified" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML("foo bar bazthings")
EquivalentXml.equivalent?(doc1,doc2, :normalize_whitespace => false).should == false
end
it "should normalize complex whitespace by default" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML(%{
things
foo
bar baz
})
EquivalentXml.equivalent?(doc1,doc2).should == true
end
it "shouldn't normalize complex whitespace if :normalize_whitespace => false is specified" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML(%{
things
foo
bar baz
})
EquivalentXml.equivalent?(doc1,doc2, :normalize_whitespace => false).should == false
end
it "should ignore comment nodes" do
doc1 = Nokogiri::XML("foo bar bazthings")
doc2 = Nokogiri::XML(%{
things
foo
bar baz
})
EquivalentXml.equivalent?(doc1,doc2).should == true
end
it "should properly handle a mixture of text and element nodes" do
doc1 = Nokogiri::XML("This phrase has bold text in it.")
doc2 = Nokogiri::XML("This phrase in has bold text it.")
EquivalentXml.equivalent?(doc1,doc2).should == false
end
end