better-html
better-html copied to clipboard
Add assertion to README.md testing block.
Rails 7.2 introduced warning for assertion-free tests. Good to recommend block with assertion (similar to rspec one) to prevent warnings.
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
It seems RuntimeError based exception is raised for invalid input on purpose.