Topic: how to check return json array in Rspec

Hi friends,
how to check return json array in Rspec
See teh below code

 books.each do |x|
         row = Hash.new
         row[:id] = x.id.to_s
         row[:cell] = [x.book_code.to_s,x.author_name]
         rows << row
      end
      
      res[:rows] =  rows
    end
    render :json => res.to_json

Re: how to check return json array in Rspec

You just do something like this:

describe "GET /foo" do
  it "returns correct JSON data" do
    get :foo
    parsed = JSON.parse(response.body)
    parsed[:rows].size.should == 5 # or whatever
    first_row = parsed[:rows].first
    first_row[:id].should == 'my_id'
    # etc.
  end
end