Introduce config.dom_testing_default_html_version
and use Rails::Dom::Testing to parse HTML in test helpers
#48682
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
Some early users of Rails edge reported test breakage due to the change in #48523 that updated test helpers to use Nokogiri's HTML5 parser.
After discussing with Rafael, he suggested that we introduce a Rails config parameter so users may opt into this change at their convenience, essentially wrapping a config param around the changes in #48523.
This PR takes that idea a step further and groups all the test helpers from
ActionView::TestCase
,ActionDispatch::Assertions
, and everything inRails::Dom::Testing
under a single config param:As a result, by setting this config to either
:html4
or:html5
, a developer can control the HTML parser used by all the test helpers in Action View, Action Dispatch, and Rails::Dom::Testing; and some assertions support overriding that default for individual tests.Detail
config.dom_testing_default_html_version
, which is injected intoDom::Rails::Testing
via the railstie in Allow user to choose the HTML parser used rails-dom-testing#109:html5
in Rails 7.1, and:html4
in earlier config versions:html4
Rails::Dom::Testing.html_document
or.html_document_fragment
to ensure the desired HTML parser is usedrails-dom-testing
to~> 2.2
Additional information
Note that integration testing across gems like this is challenging, but I have actually fired up a Rails app using this PR and rails/rails-dom-testing#109 together, and it worked as expected.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]