Testing the contents of an http response

I have a show method i’m testing, that returns some data in json format.
My tests show that something is being returned, but i want to get at it
and test the contents. I can’t work out how to do this, can anyone
help?

def test_show_gets_data_ok
get :show, :token => @given_token
assert_response
#want to say something like
#some_json = a_hash.to_json
#assert_equal(response, some_json)
end

In other words, how do i set an object equal to the response?

thanks
max

On Nov 7, 2007 6:12 AM, Max W. [email protected]
wrote:

#some_json = a_hash.to_json
#assert_equal(response, some_json)

end

In other words, how do i set an object equal to the response?

The raw response will be in @response.body

assert_equal some_json, @response.body

You put “expected” before “actual”

Bob S. wrote:

On Nov 7, 2007 6:12 AM, Max W. [email protected]
wrote:

#some_json = a_hash.to_json
#assert_equal(response, some_json)

end

In other words, how do i set an object equal to the response?

The raw response will be in @response.body

assert_equal some_json, @response.body

You put “expected” before “actual”

Great, thanks bob!

Next question, which i just realised i’d not though about before - how
do i phrase my get request to ask for the response in json format?

I know that i can get a specific url, and ask for that in json, eg

get “items/1.json”

but in my example i just want to pass through some parameters rather
than a url, eg something like -

get :show, :token => @given_token, :format => “json”

Do you know how to do that by any chance?