hello all, i am new to the RoR programming and em struck with the exception code. Can someone please verify my code: def test_show_failure get:show.{:id=>@first_id},{:user=>@user_id,:division=>@division_id} assert_respose:failure rescue NoMethodError end Thanx a lot in advance. Regards, cutelucks -- 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 -~----------~----~----~----~------~----~------~--~---
According to the API there is no assert_response: failure http://api.rubyonrails.org/ :success - Status code was 200 :redirect - Status code was in the 300-399 range :missing - Status code was 404 :error - Status code was in the 500-599 range That help? On Apr 10, 12:28 pm, cutelucks Ms <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hello all, > > i am new to the RoR programming and em struck with the exception code. > Can someone please verify my code: > > def test_show_failure > get:show.{:id=>@first_id},{:user=>@user_id,:division=>@division_id} > > assert_respose:failure > rescue NoMethodError > > end > > Thanx a lot in advance. > > Regards, > cutelucks > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gavin wrote:> According to the API there is no assert_response: failure > > http://api.rubyonrails.org/ > > :success - Status code was 200 > :redirect - Status code was in the 300-399 range > :missing - Status code was 404 > :error - Status code was in the 500-599 range > > That help? > > On Apr 10, 12:28�pm, cutelucks Ms <rails-mailing-l...@andreas-s.net>Thanx a lot. Can I use assert_raise NoMethodError? Will the code be correct then. I am confused about the rescue statement if i can use that way. -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Can you describe the function that you are testing? On Apr 10, 1:22 pm, cutelucks Ms <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Gavin wrote: > > According to the API there is no assert_response: failure > > >http://api.rubyonrails.org/ > > > :success - Status code was 200 > > :redirect - Status code was in the 300-399 range > > :missing - Status code was 404 > > :error - Status code was in the 500-599 range > > > That help? > > > On Apr 10, 12:28 pm, cutelucks Ms <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Thanx a lot. Can I use assert_raise NoMethodError? Will the code be > correct then. I am confused about the rescue statement if i can use that > way. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gavin wrote:> Can you describe the function that you are testing? > > > On Apr 10, 1:22�pm, cutelucks Ms <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>I am testing for the failure condition if the person doesn''t have the previlages to access a page. I wrote for the success condtition from the fixture which is: def test_show_success get :show ,{:id => @first_id}, { :user => @user_id, :division => @division_id } assert_response :success assert_template ''show'' assert_not_nil assigns(:bin) assert assigns(:bin).valid? end I have bin,division,user,carrier fixtures. The success condition works well. But I am unable to write for the failure condition. This is the code I wrote: def test_show_failure get :show ,{:id => @first_id}, { :user => @user_id, :division => @division_id } assert_response_NoMethodError rescue NoMethodError end I want the output as: if the login is not authorized, then NoMethodError should be raised. Thanx, cutelucks -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I would normally test this by testing the redirect (assuming you are redirecting users that do not have permission) If someone does not have permission to view a page, I normally redirect to another page and show a flash notice so in the test I would say def test_should_not_show_page_without_permission get :show, :id => @first_id, :user => @user_id, :division => @division_id assert_redirected_to notice_path # => specify your path here assert_not_nil flash[:warning] end As a tip - when naming tests, it''s good practice to use the term "should" or "should not" This helps you clearly define the behavior you are testing for. example/ def test_login_page_should_render_with_login_form end etc On Apr 10, 2:37 pm, cutelucks Ms <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Gavin wrote: > > Can you describe the function that you are testing? > > > On Apr 10, 1:22 pm, cutelucks Ms <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > I am testing for the failure condition if the person doesn''t have the > previlages to access a page. I wrote for the success condtition from the > fixture which is: > > def test_show_success > get :show ,{:id => @first_id}, { :user => @user_id, :division => > @division_id } > > assert_response :success > assert_template ''show'' > > assert_not_nil assigns(:bin) > assert assigns(:bin).valid? > end > > I have bin,division,user,carrier fixtures. The success condition works > well. > But I am unable to write for the failure condition. This is the code I > wrote: > > def test_show_failure > get :show ,{:id => @first_id}, { :user => @user_id, :division => > @division_id } > > assert_response_NoMethodError > rescue NoMethodError > end > > I want the output as: if the login is not authorized, then NoMethodError > should be raised. > > Thanx, > cutelucks > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---