Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertion to README.md testing block. #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

simi
Copy link

@simi simi commented Aug 31, 2024

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

@debano
Copy link

debano commented Oct 15, 2024

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

@simi
Copy link
Author

simi commented Oct 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants