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

ActionDispatch::Testing::TestResponse#parsed_body parse HTML with Nokogiri #47144

Merged

Commits on Jan 28, 2023

  1. ActionDispatch::Testing::TestResponse#parsed_body parse HTML with N…

    …okogiri
    
    Prior to this commit, the only out-of-the-box parsing that
    `ActionDispatch::Testing::TestResponse#parsed_body` supported was for
    `application/json` requests. This meant that `response.body ==
    response.parsed_body` for HTML requests.
    
    ```ruby
    get "/posts"
    response.content_type         # => "text/html; charset=utf-8"
    response.parsed_body.class    # => Nokogiri::HTML5::Document
    response.parsed_body.to_html  # => "<!DOCTYPE html>\n<html>\n..."
    ```
    
    Using `parsed_body` for JSON requests supports `Hash#fetch`, `Hash#dig`,
    and Ruby 3.2 destructuring assignment and pattern matching.
    
    The introduction of [Nokogiri support for pattern
    matching][nokogiri-pattern-matching] poses an opportunity to make assertions
    about the structure of the HTML response.
    
    On top of that, there is ongoing work to [introduce pattern matching
    support in MiniTest][minitest-pattern-matching].
    
    [nokogiri-pattern-matching]: sparklemotion/nokogiri#2523
    [minitest-pattern-matching]: minitest/minitest#936
    seanpdoyle committed Jan 28, 2023
    Configuration menu
    Copy the full SHA
    ad79ed0 View commit details
    Browse the repository at this point in the history