Hi, everyone, How to test a function not a action on controller test on ruby? like this: def namesomeone ( firstname, lastname) some codes end how to test this function namesomeone. who knows, please tell me, Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pat Maddox
2007-Oct-26 05:15 UTC
Re: how to test a function not a action on controller on ruby
On 10/25/07, OnRails <zzzlai-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > Hi, everyone, > How to test a function not a action on controller test on ruby? like > this: > def namesomeone ( firstname, lastname) > some codes > end > how to test this function namesomeone. > who knows, please tell me, Thanks! > > > > >I personally feel that if something is difficult to test then it''s probably not designed very well. This is almost certainly the case for you. Most likely you should move that method to the model, and it becomes obvious how to test it. Or you could write a test for an action that uses it, and verify that you get the proper output. If a method isn''t part of an object''s API, you shouldn''t be writing a test for it! That''s far too granular. You want to write tests for an object''s observable behavior. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jstepper
2007-Oct-26 18:16 UTC
Re: how to test a function not a action on controller on ruby
There is nothing bad about having a function that is not an action in a controller. Filters are a perfect example of methods in controllers that aren''t actions. Testing these methods directly is a great idea as well. Since they''re usually protected, you''ll have to use .send which will work for non-protected methods as well: @controller.send(:method, *args) or in Rspec: controller.send(:method, *args) On 10/25/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/25/07, OnRails <zzzlai-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > > > Hi, everyone, > > How to test a function not a action on controller test on ruby? like > > this: > > def namesomeone ( firstname, lastname) > > some codes > > end > > how to test this function namesomeone. > > who knows, please tell me, Thanks! > > > > > > > > > > > I personally feel that if something is difficult to test then it''s > probably not designed very well. This is almost certainly the case > for you. Most likely you should move that method to the model, and it > becomes obvious how to test it. Or you could write a test for an > action that uses it, and verify that you get the proper output. > > If a method isn''t part of an object''s API, you shouldn''t be writing a > test for it! That''s far too granular. You want to write tests for an > object''s observable behavior. > > Pat > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---