better-html icon indicating copy to clipboard operation
better-html copied to clipboard

Add assertion to README.md testing block.

Open simi opened this issue 1 year ago • 2 comments

Rails 7.2 introduced warning for assertion-free tests. Good to recommend block with assertion (similar to rspec one) to prevent warnings.

simi avatar Aug 31 '24 21:08 simi

assert_nothing_raised does not appear to be actually rescuing the exceptions raised by BetterHtml.

I'm exploring something like this (with additional handling since not all BetterHtml errors inherit from the same base class)

test "html errors in #{pathname}" do
  data = File.read(filename)

  begin
    BetterHtml::BetterErb::ErubiImplementation.new(data, filename:).validate!
    assert(true, "No exception was raised")
  rescue RuntimeError => e
    # Not all BetterHtml errors inherit from a common base class, so we need to check for module the prefix
    if e.class.name.start_with?("BetterHtml::")
      flunk("BetterHTML exception raised: #{e.class} - #{e.message}")
    else
      raise e
    end
  end
end

debano avatar Oct 15 '24 18:10 debano

It seems RuntimeError based exception is raised for invalid input on purpose.

simi avatar Oct 15 '24 18:10 simi