method
parsed_body
v7.1.3.4 -
Show latest stable
-
0 notes -
Class: ActionDispatch::TestResponse
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (38)
- 7.1.3.4 (0)
- What's this?
parsed_body()
public
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 # => Nokogiri::HTML5::Document response.parsed_body.to_html # => "<!DOCTYPE html>\n<html>\n..." assert_pattern { response.parsed_body.at("main") => { content: "Hello, world" } } response.parsed_body.at("main") => {name:, content:} assert_equal "main", name assert_equal "Some main content", content get "/posts.json" response.content_type # => "application/json; charset=utf-8" response.parsed_body.class # => Array response.parsed_body # => [{"id"=>42, "title"=>"Title"},... assert_pattern { response.parsed_body => [{ id: 42 }] } get "/posts/42.json" response.content_type # => "application/json; charset=utf-8" response.parsed_body.class # => ActiveSupport::HashWithIndifferentAccess response.parsed_body # => {"id"=>42, "title"=>"Title"} assert_pattern { response.parsed_body => [{ title: /title/i }] } response.parsed_body => {id:, title:} assert_equal 42, id assert_equal "Title", title