Methods
Public Class methods
[ show source ]
# File actionpack/lib/action_controller/assertions/dom_assertions.rb, line 4 4: def self.strip_whitespace!(nodes) 5: nodes.reject! do |node| 6: if node.is_a?(HTML::Text) 7: node.content.strip! 8: node.content.empty? 9: else 10: strip_whitespace! node.children 11: false 12: end 13: end 14: end
Public Instance methods
Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
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")
[ show source ]
# File actionpack/lib/action_controller/assertions/dom_assertions.rb, line 23 23: def assert_dom_equal(expected, actual, message = "") 24: clean_backtrace do 25: expected_dom = HTML::Document.new(expected).root 26: actual_dom = HTML::Document.new(actual).root 27: DomAssertions.strip_whitespace!(expected_dom.children) 28: DomAssertions.strip_whitespace!(actual_dom.children) 29: 30: full_message = build_message(message, "<?> expected but was\n<?>.", expected_dom.to_s, actual_dom.to_s) 31: assert_block(full_message) { expected_dom == actual_dom } 32: end 33: end
The negated form of assert_dom_equal.
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")
[ show source ]
# File actionpack/lib/action_controller/assertions/dom_assertions.rb, line 42 42: def assert_dom_not_equal(expected, actual, message = "") 43: clean_backtrace do 44: expected_dom = HTML::Document.new(expected).root 45: actual_dom = HTML::Document.new(actual).root 46: DomAssertions.strip_whitespace!(expected_dom.children) 47: DomAssertions.strip_whitespace!(actual_dom.children) 48: 49: full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s) 50: assert_block(full_message) { expected_dom != actual_dom } 51: end 52: end