For the methods defined as private,we need to test it? For the reason that the private methods are used within the public methods,so we need not to test the private methods as long as the public methods are tested? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
it''s up to you. if you''re satisfied that the private method is working properly in the course of testing the public methods then fine, otherwise you should be able to call the private method like: @my_object.send(:private_method_name, arg1, arg2) On Nov 14, 10:16 am, daociyiyou <chey...-/E1597aS9LRv1O+Z8WTAqQ@public.gmane.org> wrote:> For the methods defined as private,we need to test it? > For the reason that the private methods are used within the public > methods,so we need not to test the private methods as long as the > public methods are tested?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
daociyiyou wrote:> For the methods defined as private,we need to test it? > For the reason that the private methods are used within the public > methods,so we need not to test the private methods as long as the > public methods are tested?A very clear discussion of the topic by one of the best testers in the Ruby world (in my opinion): http://evang.eli.st/blog/2008/10/27/testing-protected-and-private-methods-in-ruby HTH Paul -- 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 -~----------~----~----~----~------~----~------~--~---
Jeff Emminger wrote:> it''s up to you. if you''re satisfied that the private method is > working properly in the course of testing the public methods then > fine, otherwise you should be able to call the private method like: > > @my_object.send(:private_method_name, arg1, arg2)I believe that I read somewhere that a future version of Ruby will be "fixed" to not allow using "send" to call private and protected methods. Which is really the behavior it should have had in the first place. Allowing this breaks the rules of encapsulation. A test case class is external to the class being tested, and like any other class SHOULD NOT have access to private data. Given that a private method should only ever be called from inside the confines of the class then you must access them via the public API and therefore tested though that public API. Test cases are clients of classes being tested in the same way any other class would be a client. This means that your tests, or specs, should test the behavior of the class through that same API. Theses tests should therefore be complete enough to exercise the "behavior" of the underlying private data and methods of the class being tested. At least this is my own understanding. Feel free to disagree... -- 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 14, 11:27 am, Robert Walker <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Jeff Emminger wrote: > > it''s up to you. if you''re satisfied that the private method is > > working properly in the course of testing the public methods then > > fine, otherwise you should be able to call the private method like: > > > @my_object.send(:private_method_name, arg1, arg2) > > I believe that I read somewhere that a future version of Ruby will be > "fixed" to not allow using "send" to call private and protected methods. > Which is really the behavior it should have had in the first place. > Allowing this breaks the rules of encapsulation. > > A test case class is external to the class being tested, and like any > other class SHOULD NOT have access to private data. Given that a private > method should only ever be called from inside the confines of the class > then you must access them via the public API and therefore tested though > that public API. > > Test cases are clients of classes being tested in the same way any other > class would be a client. This means that your tests, or specs, should > test the behavior of the class through that same API. Theses tests > should therefore be complete enough to exercise the "behavior" of the > underlying private data and methods of the class being tested. > > At least this is my own understanding. Feel free to disagree... > --Yeah, that''s probably the better route. If you''re resorting to calling a protected or private method directly, then you either aren''t testing the public methods well enough or you haven''t designed the software well enough --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you very much! I have understood it very clearly. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---