Froze rails gems
[depot.git] / vendor / rails / actionpack / lib / action_controller / assertions / dom_assertions.rb
1 module ActionController
2 module Assertions
3 module DomAssertions
4 # Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
5 #
6 # ==== Examples
7 #
8 # # assert that the referenced method generates the appropriate HTML string
9 # assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com")
10 #
11 def assert_dom_equal(expected, actual, message = "")
12 clean_backtrace do
13 expected_dom = HTML::Document.new(expected).root
14 actual_dom = HTML::Document.new(actual).root
15 full_message = build_message(message, "<?> expected to be == to\n<?>.", expected_dom.to_s, actual_dom.to_s)
16
17 assert_block(full_message) { expected_dom == actual_dom }
18 end
19 end
20
21 # The negated form of +assert_dom_equivalent+.
22 #
23 # ==== Examples
24 #
25 # # assert that the referenced method does not generate the specified HTML string
26 # assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com")
27 #
28 def assert_dom_not_equal(expected, actual, message = "")
29 clean_backtrace do
30 expected_dom = HTML::Document.new(expected).root
31 actual_dom = HTML::Document.new(actual).root
32 full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s)
33
34 assert_block(full_message) { expected_dom != actual_dom }
35 end
36 end
37 end
38 end
39 end