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

Allow user to choose the HTML parser used #109

Merged

Conversation

flavorjones
Copy link
Member

@flavorjones flavorjones commented Jul 6, 2023

In this PR we:

  • introduce module attribute Rails::Dom::Testing.default_html_version
    • this attribute defaults to :html4 but can be set to :html5
  • update assertions that parse HTML to accept a kwarg html_version:, to override the default:
    • assert_dom_equal
    • assert_dom_not_equal
    • assert_dom_email
    • assert_dom_encoded
  • introduce and use helper methods Rails::Dom::Testing.html_document and .html_document_fragment
    • these return the appropriate parser class based on default_html_version and an optional html_version: kwarg
  • introduce a railstie that sets Rails::Dom::Testing.default_html_version based on the Rails config param config.dom_testing_default_html_version

This PR is a dependency of rails/rails#48682 which will:

and minor cleanup in the README
Also provide helper methods:

- `Rails::Dom::Testing.html_document`
- `Rails::Dom::Testing.html_document_fragment`

which will return a parser class based on the default or an optional
injected `html_version:` kwarg.

These methods will raise an exception if the configuration cannot be
honored (e.g., the HTML5 parser isn't supported on the platform).
via an `html_version` kwarg:

- assert_dom_equal and assert_dom_not_equal
- assert_dom_encoded
- assert_dom_email

The remaining assertions all rely on `document_root_element` to return
the DOM (meaning we'll have to make changes to Rails).
@flavorjones flavorjones changed the title Allow used to choose the HTML parser used Allow user to choose the HTML parser used Jul 6, 2023
@flavorjones flavorjones requested a review from rafaelfranca July 7, 2023 12:51
@flavorjones flavorjones force-pushed the flavorjones-dom-testing-html-version branch from 9de7532 to 2beaa6b Compare July 7, 2023 21:29
@flavorjones flavorjones force-pushed the flavorjones-dom-testing-html-version branch from 2beaa6b to 144f8e5 Compare August 3, 2023 12:54
@flavorjones
Copy link
Member Author

I've fixed this PR to use config.after_initialize to make sure application initializers take effect.

@rafaelfranca rafaelfranca merged commit 549dc7e into rails:main Aug 3, 2023
@flavorjones flavorjones deleted the flavorjones-dom-testing-html-version branch August 3, 2023 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants