instance method parsed_body

Ruby on Rails 7.0.10

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

parsed_body()

Returns a parsed body depending on the response MIME type. When a parser corresponding to the MIME type is not found, it returns the raw body.

Examples

get "/posts"
response.content_type      # => "text/html; charset=utf-8"
response.parsed_body.class # => String
response.parsed_body       # => "<!DOCTYPE html>\n<html>\n..."

get "/posts.json"
response.content_type      # => "application/json; charset=utf-8"
response.parsed_body.class # => Array
response.parsed_body       # => [{"id"=>42, "title"=>"Title"},...

get "/posts/42.json"
response.content_type      # => "application/json; charset=utf-8"
response.parsed_body.class # => Hash
response.parsed_body       # => {"id"=>42, "title"=>"Title"}
Source
# File actionpack/lib/action_dispatch/testing/test_response.rb, line 35
    def parsed_body
      @parsed_body ||= response_parser.call(body)
    end

Defined in actionpack/lib/action_dispatch/testing/test_response.rb line 35 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionDispatch::TestResponse

Type at least 2 characters to search.

↑↓ navigate · open · esc close