From 9dac1e8b8f05ab047cd1a514b42a190792eb6ce4 Mon Sep 17 00:00:00 2001 From: Timm Date: Fri, 16 Aug 2013 16:17:44 +0200 Subject: Removed duplication in assert_dom_equal and assert_dom_not_equal. --- actionview/lib/action_view/testing/assertions/dom.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'actionview') 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 'Apples', 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 'Apples', 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?+ -- cgit v1.2.3