Hey, I''m wondering about the distinction between writing test methods like 1. def test_something_to_test end and like 2. test "something to test" do end It seems like there''s no difference. I did notice, however, that #2 can''t be done in a class that extends Test::Unit::TestCase, while it can be done in one that extends ActionController::TestCase. I also noticed that #1 works for classes that extend either. So which should I use? What is the difference? Thanks in advance. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 11, 3:45 pm, David Zhang <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey, I''m wondering about the distinction between writing test methods > like > > 1. > def test_something_to_test > > end > > and like > > 2. > test "something to test" do > > end > > It seems like there''s no difference. I did notice, however, that #2 > can''t be done in a class that extends Test::Unit::TestCase, while it can > be done in one that extends ActionController::TestCase. I also noticed > that #1 works for classes that extend either. > > So which should I use? What is the difference? >test "..." do end is added by Active Support (as part of ActiveSupport::TestCase (which ActionController::TestCase inherits from)) which is why you can''t use it in a Test::Unit::TestCase subclass. It''s really just a stylistic difference. One of the few differences I''m aware of is that Active Support''s test "..." allows you not to provide a method body (and test runs will then tell you about that) and it will raise an exception if you try to create two tests with the same name (whereas when just defining instance methods the 2nd definition would overwrite the first Fred> Thanks in advance. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Frederick Cheung wrote:> ...One of the few differences > I''m aware of is that Active Support''s test "..." allows you not to > provide a method body (and test runs will then tell you about that) > and it will raise an exception if you try to create two tests with the > same name (whereas when just defining instance methods the 2nd > definition would overwrite the first > > FredThanks, Fred. But what''s the advantage of not providing a method body? And for your second point ("rais[ing] and exception"): so if I have a class that inherits from ActiveSupport::TestCase, creating 2 methods with identical names will cause an error, while if I have a class that inherits from Test::Unit::TestCase, creating 2 methods with identical names will NOT cause an error but instead result in the use of the 2nd definition over the 1st? Just making sure I understand...thanks again! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 12, 2:44 pm, "Daze Z." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > ...One of the few differences > > I''m aware of is that Active Support''s test "..." allows you not to > > provide a method body (and test runs will then tell you about that) > > and it will raise an exception if you try to create two tests with the > > same name (whereas when just defining instance methods the 2nd > > definition would overwrite the first > > > Fred > > Thanks, Fred. > But what''s the advantage of not providing a method body? >I think it''s just a way of spelling out what tests you want to write (and be reminded that they''re still unwritten)> And for your second point ("rais[ing] and exception"): so if I have a > class that inherits from ActiveSupport::TestCase, creating 2 methods > with identical names will cause an error, while if I have a class that > inherits from Test::Unit::TestCase, creating 2 methods with identical > names will NOT cause an error but instead result in the use of the 2nd > definition over the 1st? >Yup.> Just making sure I understand...thanks again! > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Frederick Cheung wrote:> On Jul 12, 2:44�pm, "Daze Z." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Thanks, Fred. >> But what''s the advantage of not providing a method body? >> > > I think it''s just a way of spelling out what tests you want to write > (and be reminded that they''re still unwritten)Oh, I see. But couldn''t you not provide a method body for a method in any class? So you could also do it in one that extends Test::Unit::TestCase...couldn''t you? How is it "[o]ne of the few differences"? thanks again! this site''s pretty good... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.