From cb215c9f7d9e4a9d469abdbd87c0dd909161db95 Mon Sep 17 00:00:00 2001 From: Timm Date: Sat, 20 Jul 2013 12:47:10 +0200 Subject: Simplified the first delete_if loop in assert_select to use Loofah's text method. --- .../action_dispatch/testing/assertions/selector.rb | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index c63dd1ca8a..43eb899348 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -188,20 +188,11 @@ module ActionDispatch content_mismatch = nil if match_with = equals[:text] matches.delete_if do |match| - text = "" - stack = match.children.reverse - while node = stack.pop - if node.tag? - stack.concat node.children.reverse - else - content = node.content - text << content - end - end + text = match.text text.strip! unless NO_STRIP.include?(match.name) text.sub!(/\A\n/, '') if match.name == "textarea" - unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s) - content_mismatch ||= sprintf("<%s> expected but was\n<%s>", match_with, text) + unless content_matches?(match_with, text) + content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, text) true end end @@ -209,8 +200,8 @@ module ActionDispatch matches.delete_if do |match| html = match.children.map(&:to_s).join html.strip! unless NO_STRIP.include?(match.name) - unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s) - content_mismatch ||= sprintf("<%s> expected but was\n<%s>", match_with, html) + unless content_matches?(match_with, html) + content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, html) true end end @@ -355,6 +346,14 @@ module ActionDispatch end protected + def content_matches?(match_with, content) + if match_with.is_a?(Regexp) + content =~ match_with + else + content == match_with.to_s + end + end + class Selector #:nodoc: attr_accessor :root, :css_selector -- cgit v1.2.3