Browse files

Ignore the order of attributes (closes #5).

  • Loading branch information...
1 parent ecc8e88 commit a3b2f4c511c65956a131ee26ec763a9c8826be37 @postmodern committed Apr 20, 2013
Showing with 20 additions and 9 deletions.
  1. +1 −1 lib/nokogiri/diff/xml/node.rb
  2. +19 −8 spec/diff_spec.rb
View
2 lib/nokogiri/diff/xml/node.rb
@@ -48,7 +48,7 @@ def tdiff_equal(node)
#
def tdiff_each_child(node,&block)
if node.kind_of?(Nokogiri::XML::Element)
- node.attribute_nodes.each(&block)
+ node.attribute_nodes.sort_by(&:name).each(&block)
end
node.children.each(&block)
View
27 spec/diff_spec.rb
@@ -3,20 +3,22 @@
describe "nokogiri/diff" do
let(:contents) { '<div><p>one</p></div>' }
- let(:doc) { Nokogiri::XML(contents) }
+ let(:doc) { Nokogiri::XML(contents) }
- let(:added_text) { Nokogiri::XML('<div><p>one</p>two</div>') }
+ let(:added_text) { Nokogiri::XML('<div><p>one</p>two</div>') }
let(:added_element) { Nokogiri::XML('<div><p>one</p><p>two</p></div>') }
- let(:added_attr) { Nokogiri::XML('<div><p id="1">one</p></div>') }
+ let(:added_attr) { Nokogiri::XML('<div><p id="1">one</p></div>') }
+ let(:added_attrs) { Nokogiri::XML('<div><p id="1" class="2">one</p></div>') }
- let(:changed_text) { Nokogiri::XML('<div><p>two</p></div>') }
- let(:changed_element) { Nokogiri::XML('<div><span>one</span></div>') }
- let(:changed_attr_name) { Nokogiri::XML('<div><p i="1">one</p></div>') }
+ let(:changed_text) { Nokogiri::XML('<div><p>two</p></div>') }
+ let(:changed_element) { Nokogiri::XML('<div><span>one</span></div>') }
+ let(:changed_attr_name) { Nokogiri::XML('<div><p i="1">one</p></div>') }
let(:changed_attr_value) { Nokogiri::XML('<div><p id="2">one</p></div>') }
+ let(:changed_attr_order) { Nokogiri::XML('<div><p class="2" id="1">one</p></div>') }
- let(:removed_text) { Nokogiri::XML('<div><p></p>two</div>') }
+ let(:removed_text) { Nokogiri::XML('<div><p></p>two</div>') }
let(:removed_element) { Nokogiri::XML('<div></div>') }
- let(:removed_attr) { Nokogiri::XML('<div><p>one</p></div>') }
+ let(:removed_attr) { Nokogiri::XML('<div><p>one</p></div>') }
it "should add #diff to Nokogiri::XML::Docuemnt" do
doc.should respond_to(:diff)
@@ -92,6 +94,12 @@
changes[4][1].should == added_element.at('//p[2]/text()')
end
+ it "should ignore when attribute order changes" do
+ changes = added_attrs.at('p').diff(changed_attr_order.at('p')).to_a
+
+ changes.all? { |change| change[0] == ' ' }.should be_true
+ end
+
it "should determine when attributes are added" do
changes = doc.at('p').diff(added_attr.at('p')).to_a
@@ -206,6 +214,9 @@
changes[2][1].should == added_element.at('//p[2]')
end
+ it "should ignore when attributes change order" do
+ end
+
it "should determine when attributes are removed" do
changes = added_attr.at('div').diff(removed_attr.at('div')).to_a

0 comments on commit a3b2f4c

Please sign in to comment.