Module: Scarpe::Test::HTMLAssertions

Defined in:
lib/scarpe/components/unit_test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#assert_contains_html(actual_html, expected_tag, **opts) { ... } ⇒ void

This method returns an undefined value.

Assert that ‘actual_html` includes `expected_tag` with `opts`. This uses Scarpe’s HTML tag-based renderer to render the tag and options into text, and valides that the full HTML contains that tag.

Parameters:

  • actual_html (String)

    the html to compare to

  • expected_tag (String, Symbol)

    the HTML tag, used to send a method call

  • opts

    keyword options passed to the tag method call

Yields:

  • block passed to the tag method call.

See Also:



252
253
254
255
256
257
258
# File 'lib/scarpe/components/unit_test_helpers.rb', line 252

def assert_contains_html(actual_html, expected_tag, **opts, &block)
  expected_html = Scarpe::Components::HTML.render do |h|
    h.public_send(expected_tag, opts, &block)
  end

  assert actual_html.include?(expected_html), "Expected #{actual_html.inspect} to include #{expected_html.inspect}!"
end

#assert_html(actual_html, expected_tag, **opts) { ... } ⇒ void

This method returns an undefined value.

Assert that ‘actual_html` is the same as `expected_tag` with `opts`. This uses Scarpe’s HTML tag-based renderer to render the tag and options into text, and valides that the text is the same.

Parameters:

  • actual_html (String)

    the html to compare to

  • expected_tag (String, Symbol)

    the HTML tag, used to send a method call

  • opts

    keyword options passed to the tag method call

Yields:

  • block passed to the tag method call.

See Also:



233
234
235
236
237
238
239
# File 'lib/scarpe/components/unit_test_helpers.rb', line 233

def assert_html(actual_html, expected_tag, **opts, &block)
  expected_html = Scarpe::Components::HTML.render do |h|
    h.public_send(expected_tag, opts, &block)
  end

  assert_equal expected_html, actual_html
end