How to check for a JSON response using RSpec?

后端 未结 14 1308
谎友^
谎友^ 2020-11-29 16:03

I have the following code in my controller:

format.json { render :json => { 
        :flashcard  => @flashcard,
        :lesson     => @lesson,
             


        
14条回答
  •  不知归路
    2020-11-29 16:54

    You could parse the response body like this:

    parsed_body = JSON.parse(response.body)
    

    Then you can make your assertions against that parsed content.

    parsed_body["foo"].should == "bar"
    

提交回复
热议问题