2009-04-30 12:55:53 -04:00
|
|
|
module ActionDispatch
|
2006-09-03 16:18:06 -04:00
|
|
|
module Assertions
|
|
|
|
module DomAssertions
|
2007-03-27 10:04:06 -04:00
|
|
|
# Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
|
2007-12-05 09:40:42 -05:00
|
|
|
#
|
|
|
|
# ==== Examples
|
|
|
|
#
|
|
|
|
# # 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")
|
|
|
|
#
|
2007-09-09 19:03:32 -04:00
|
|
|
def assert_dom_equal(expected, actual, message = "")
|
2009-04-30 12:40:29 -04:00
|
|
|
expected_dom = HTML::Document.new(expected).root
|
|
|
|
actual_dom = HTML::Document.new(actual).root
|
|
|
|
full_message = build_message(message, "<?> expected to be == to\n<?>.", expected_dom.to_s, actual_dom.to_s)
|
2007-09-09 19:03:32 -04:00
|
|
|
|
2009-04-30 12:40:29 -04:00
|
|
|
assert_block(full_message) { expected_dom == actual_dom }
|
2006-09-03 16:18:06 -04:00
|
|
|
end
|
|
|
|
|
2007-03-27 10:04:06 -04:00
|
|
|
# The negated form of +assert_dom_equivalent+.
|
2007-12-05 09:40:42 -05:00
|
|
|
#
|
|
|
|
# ==== Examples
|
|
|
|
#
|
|
|
|
# # 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")
|
|
|
|
#
|
2007-09-09 19:03:32 -04:00
|
|
|
def assert_dom_not_equal(expected, actual, message = "")
|
2009-04-30 12:40:29 -04:00
|
|
|
expected_dom = HTML::Document.new(expected).root
|
|
|
|
actual_dom = HTML::Document.new(actual).root
|
|
|
|
full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s)
|
2007-09-09 19:03:32 -04:00
|
|
|
|
2009-04-30 12:40:29 -04:00
|
|
|
assert_block(full_message) { expected_dom != actual_dom }
|
2006-09-03 16:18:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-12-05 09:40:42 -05:00
|
|
|
end
|