How to test JSON result from Ruby on Rails functional tests?

前端 未结 9 517
暗喜
暗喜 2021-01-29 23:35

How can I assert my Ajax request and test the JSON output from Ruby on Rails functional tests?

9条回答
  •  孤城傲影
    2021-01-29 23:59

    Also for short JSON responses you can simply match a string of the JSON to @response.body. This prevents having to rely on yet another gem.

    assert_equal '{"total_votes":1}', @response.body
    

提交回复
热议问题