How can I assert my Ajax request and test the JSON output from Ruby on Rails functional tests?
Use ActionDispatch::TestResponse#parsed_body.
Example:
user = @response.parsed_body
assert_equal "Mike", user['name']
Use JSON.parse
, which takes a string as input and returns a Ruby hash that the JSON represents.
Example:
user = JSON.parse(@response.body)
assert_equal "Mike", user['name']