How to check for a JSON response using RSpec?

后端 未结 14 1296
谎友^
谎友^ 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:35

    Simple and easy to way to do this.

    # set some variable on success like :success => true in your controller
    controller.rb
    render :json => {:success => true, :data => data} # on success
    
    spec_controller.rb
    parse_json = JSON(response.body)
    parse_json["success"].should == true
    

提交回复
热议问题