Module ActionController::Assertions::DomAssertions
In: vendor/rails/actionpack/lib/action_controller/assertions/dom_assertions.rb

Methods

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")

[Source]

    # File vendor/rails/actionpack/lib/action_controller/assertions/dom_assertions.rb, line 11
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

The negated form of assert_dom_equivalent.

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")

[Source]

    # File vendor/rails/actionpack/lib/action_controller/assertions/dom_assertions.rb, line 28
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

[Validate]