class ActionDispatch::TestResponse
def parsed_body
assert_equal 42, id
response.parsed_body => {id:, title:}
assert_pattern { response.parsed_body => [{ title: /title/i }] }
response.parsed_body # => {"id"=>42, "title"=>"Title"}
response.parsed_body.class # => ActiveSupport::HashWithIndifferentAccess
response.content_type # => "application/json; charset=utf-8"
get "/posts/42.json"
assert_pattern { response.parsed_body => [{ id: 42 }] }
response.parsed_body # => [{"id"=>42, "title"=>"Title"},...
response.parsed_body.class # => Array
response.content_type # => "application/json; charset=utf-8"
get "/posts.json"
assert_equal "Some main content", content
assert_equal "main", name
response.parsed_body.at("main") => {name:, content:}
assert_pattern { response.parsed_body.at("main") => { content: "Hello, world" } }
response.parsed_body.to_html # => "\n\n..."
response.parsed_body.class # => Nokogiri::HTML5::Document
response.content_type # => "text/html; charset=utf-8"
get "/posts"
==== Examples
corresponding to the MIME type is not found, it returns the raw body.
Returns a parsed body depending on the response MIME type. When a parser
def parsed_body @parsed_body ||= response_parser.call(body) end