aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib
diff options
context:
space:
mode:
authorTimm <kaspth@gmail.com>2013-08-16 16:17:44 +0200
committerTimm <kaspth@gmail.com>2014-06-16 21:04:06 +0200
commit9dac1e8b8f05ab047cd1a514b42a190792eb6ce4 (patch)
tree97020c9d89d8473ebdcc54340312ed722b784664 /actionview/lib
parent86c6f5b1d9ef79dd69724d01afe5c6dfb274edb8 (diff)
downloadrails-9dac1e8b8f05ab047cd1a514b42a190792eb6ce4.tar.gz
rails-9dac1e8b8f05ab047cd1a514b42a190792eb6ce4.tar.bz2
rails-9dac1e8b8f05ab047cd1a514b42a190792eb6ce4.zip
Removed duplication in assert_dom_equal and assert_dom_not_equal.
Diffstat (limited to 'actionview/lib')
-rw-r--r--actionview/lib/action_view/testing/assertions/dom.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/actionview/lib/action_view/testing/assertions/dom.rb b/actionview/lib/action_view/testing/assertions/dom.rb
index 56edf48770..751c88c2e0 100644
--- a/actionview/lib/action_view/testing/assertions/dom.rb
+++ b/actionview/lib/action_view/testing/assertions/dom.rb
@@ -6,9 +6,7 @@ module ActionView
# # assert that the referenced method generates the appropriate HTML string
# assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com")
def assert_dom_equal(expected, actual, message = nil)
- expected_dom, actual_dom = doms_from_strings(expected, actual)
- message ||= "Expected: #{expected_dom}\nActual: #{actual_dom}"
- assert compare_doms(expected_dom, actual_dom), message
+ assert dom_assertion(message, expected, actual)
end
# The negated form of +assert_dom_equal+.
@@ -16,15 +14,14 @@ module ActionView
# # assert that the referenced method does not generate the specified HTML string
# assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com")
def assert_dom_not_equal(expected, actual, message = nil)
- expected_dom, actual_dom = doms_from_strings(expected, actual)
- message ||= "Expected: #{expected_dom}\nActual: #{actual_dom}"
- assert_not compare_doms(expected_dom, actual_dom), message
+ assert_not dom_assertion(message, expected, actual)
end
protected
- # +doms_from_strings+ creates a Loofah::HTML::DocumentFragment for every string in strings
- def doms_from_strings(*strings)
- strings.map { |str| Loofah.fragment(str) }
+ def dom_assertion(message = nil, *html_strings)
+ expected, actual = html_strings.map { |str| Loofah.fragment(str) }
+ message ||= "Expected: #{expected}\nActual: #{actual}"
+ return compare_doms(expected, actual), message
end
# +compare_doms+ takes two doms loops over all their children and compares each child via +equal_children?+