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

前端 未结 9 610
暗喜
暗喜 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-30 00:14

    Rails has JSON support built in:

    def json_response
        ActiveSupport::JSON.decode @response.body
    end
    

    No need for a plugin

    Then you can do something like this:

    assert_equal "Mike", json_response['name']
    

提交回复
热议问题