diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index ffaa78af45373..2117a0bac941a 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,7 @@ +* Parse `ActionView::TestCase#rendered` HTML content as `Nokogiri::XML::DocumentFragment` instead of `Nokogiri::XML::Document` + + *Sean Doyle* + * Rename `ActionView::TestCase::Behavior::{Content,RenderedViewContent}` *Sean Doyle* diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index a5a026efbadad..74f5fd83234e2 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -202,7 +202,7 @@ def include_helper_modules! setup :setup_with_controller - register_parser :html, -> rendered { Rails::Dom::Testing.html_document.parse(rendered).root } + register_parser :html, -> rendered { Rails::Dom::Testing.html_document_fragment.parse(rendered) } register_parser :json, -> rendered { JSON.parse(rendered, object_class: ActiveSupport::HashWithIndifferentAccess) } ActiveSupport.run_load_hooks(:action_view_test_case, self) diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index 6e8ad38f8e16a..163ec700d2255 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -397,12 +397,13 @@ class RenderedViewContentTest < ActionView::TestCase end class HTMLParserTest < ActionView::TestCase - test "rendered.html is a Nokogiri::XML::Element" do + test "rendered.html is a Nokogiri::XML::DocumentFragment" do developer = DeveloperStruct.new("Eloy") render "developers/developer", developer: developer - assert_kind_of Nokogiri::XML::Element, rendered.html + assert_kind_of Nokogiri::XML::DocumentFragment, rendered.html + assert_equal rendered.to_s, rendered.html.to_s assert_equal developer.name, document_root_element.text end @@ -425,6 +426,7 @@ class JSONParserTest < ActionView::TestCase render formats: :json, partial: "developers/developer", locals: { developer: developer } assert_kind_of ActiveSupport::HashWithIndifferentAccess, rendered.json + assert_equal rendered.to_s, rendered.json.to_json assert_equal developer.name, rendered.json[:name] end end