From d6067e81934a491dc1bd6262930155d64f9df658 Mon Sep 17 00:00:00 2001 From: Timm Date: Sat, 17 Aug 2013 12:39:19 +0200 Subject: Changed attributes_are_equal? to equal_attribute_nodes? which takes attribute_nodes instead of nodes. --- actionview/lib/action_view/testing/assertions/dom.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'actionview/lib/action_view/testing/assertions') diff --git a/actionview/lib/action_view/testing/assertions/dom.rb b/actionview/lib/action_view/testing/assertions/dom.rb index 8df03445a8..556b70a196 100644 --- a/actionview/lib/action_view/testing/assertions/dom.rb +++ b/actionview/lib/action_view/testing/assertions/dom.rb @@ -27,7 +27,7 @@ module ActionView # +compare_doms+ takes two doms loops over all their children and compares each child via +equal_children?+ def compare_doms(expected, actual) return false unless expected.children.size == actual.children.size - + expected.children.each_with_index do |child, i| return false unless equal_children?(child, actual.children[i]) end @@ -42,7 +42,8 @@ module ActionView case child.type when Nokogiri::XML::Node::ELEMENT_NODE - child.name == other_child.name && attributes_are_equal?(child, other_child) + child.name == other_child.name && + equal_attribute_nodes?(child.attribute_nodes, other_child.attribute_nodes) else child.to_s == other_child.to_s end @@ -51,12 +52,12 @@ module ActionView # +attributes_are_equal?+ sorts elements attributes by name and compares # each attribute by calling +equal_attribute?+ # If those are +true+ the attributes are considered equal - def attributes_are_equal?(element, other_element) - first_nodes = element.attribute_nodes.sort_by { |a| a.name } - other_nodes = other_element.attribute_nodes.sort_by { |a| a.name } + def equal_attribute_nodes?(nodes, other_nodes) + return false unless nodes.size == other_nodes.size + nodes = nodes.sort_by(&:name) + other_nodes = other_nodes.sort_by(&:name) - return false unless first_nodes.size == other_nodes.size - first_nodes.each_with_index do |attr, i| + nodes.each_with_index do |attr, i| return false unless equal_attribute?(attr, other_nodes[i]) end true -- cgit v1.2.3