Module: Rails::Dom::Testing::Assertions::DomAssertions

Included in:
Rails::Dom::Testing::Assertions
Defined in:
lib/rails/dom/testing/assertions/dom_assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_dom_equal(expected, actual, message = nil) ⇒ Object

Test two HTML strings for equivalency (e.g., equal even when attributes are in another order)

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

10
11
12
13
14
# File 'lib/rails/dom/testing/assertions/dom_assertions.rb', line 10

def assert_dom_equal(expected, actual, message = nil)
  expected_dom, actual_dom = fragment(expected), fragment(actual)
  message ||= "Expected: #{expected}\nActual: #{actual}"
  assert compare_doms(expected_dom, actual_dom), message
end

#assert_dom_not_equal(expected, actual, message = nil) ⇒ Object

The negated form of assert_dom_equal.

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

20
21
22
23
24
# File 'lib/rails/dom/testing/assertions/dom_assertions.rb', line 20

def assert_dom_not_equal(expected, actual, message = nil)
  expected_dom, actual_dom = fragment(expected), fragment(actual)
  message ||= "Expected: #{expected}\nActual: #{actual}"
  assert_not compare_doms(expected_dom, actual_dom), message
end