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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 7, 2007 6:12 AM, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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?The raw response will be in @response.body assert_equal some_json, @response.body You put "expected" before "actual" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter wrote:> On Nov 7, 2007 6:12 AM, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---