aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorTimm <kaspth@gmail.com>2013-07-20 12:47:10 +0200
committerTimm <kaspth@gmail.com>2014-06-15 23:40:56 +0200
commitcb215c9f7d9e4a9d469abdbd87c0dd909161db95 (patch)
tree0dff7cc7d83d6d567818a05eddaf9f292380daa3 /actionpack
parent328512ea5f30dd2e408bfb002fab9ed0e1b391ce (diff)
downloadrails-cb215c9f7d9e4a9d469abdbd87c0dd909161db95.tar.gz
rails-cb215c9f7d9e4a9d469abdbd87c0dd909161db95.tar.bz2
rails-cb215c9f7d9e4a9d469abdbd87c0dd909161db95.zip
Simplified the first delete_if loop in assert_select to use Loofah's text method.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/selector.rb27
1 files 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