Skip to content

Files

Latest commit

 

History

History
31 lines (20 loc) · 882 Bytes

Rails-ResponseParsedBody.md

File metadata and controls

31 lines (20 loc) · 882 Bytes

Pattern: Missing use of response.parsed_body

Issue: -

Description

Prefer response.parsed_body to JSON.parse(response.body).

This rule is unsafe because Content-Type may not be application/json. For example, the proprietary Content-Type provided by corporate entities such as application/vnd.github+json is not supported at response.parsed_body by default, so you still have to use JSON.parse(response.body) there.

Examples

# bad
JSON.parse(response.body)

# good
response.parsed_body

Configurable attributes

Name Default value Configurable values
Include +spec/controllers/**/*.rb+, +spec/requests/**/*.rb+, +test/controllers/**/*.rb+, +test/integration/**/*.rb+ Array

Further Reading