I am running tests and I would like to include logger.info("\n\n STARTING #{get_method_name} \n\n") in the beginning of each method in my account_test.rb file. How would I do that without having to put it in each method?? -- 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 10 Sep 2008, at 17:21, Joel Saltzmanjoelh wrote:> > I am running tests and I would like to include > > logger.info("\n\n STARTING #{get_method_name} \n\n") > > in the beginning of each method in my account_test.rb file. How > would I > do that without having to put it in each method??stick it in the setup method. Fred> > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> stick it in the setup method. > > FredWould that just be setup logger.info("\n\n STARTING #{get_method_name} \n\n") -- 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 -~----------~----~----~----~------~----~------~--~---
you first need to make sure that logger is defined in test_helper. If you have not done that, you need to add: def logger RAILS_DEFAULT_LOGGER end in your test_helper.rb then in your unit or functional tests, you can add the logger message as part of the setup method which runs once before every action in the test Def setup logger.info .... end the setup method is within the class definition I am assuming that you defined the get_method_name in test_helper as well. On Sep 10, 11:35 am, Joel Saltzmanjoelh <rails-mailing-l...@andreas- s.net> wrote:> Frederick Cheung wrote: > > stick it in the setup method. > > > Fred > > Would that just be > > setup logger.info("\n\n STARTING #{get_method_name} \n\n") > -- > 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 -~----------~----~----~----~------~----~------~--~---
saljamil wrote:> you first need to make sure that logger is defined in test_helper. If > you have not done that, you need to add: > def logger > RAILS_DEFAULT_LOGGER > end > in your test_helper.rb > > then in your unit or functional tests, you can add the logger message > as part of the setup method which runs once before every action in the > test > Def setup > logger.info .... > end > the setup method is within the class definition > > I am assuming that you defined the get_method_name in test_helper as > well. > > On Sep 10, 11:35�am, Joel Saltzmanjoelh <rails-mailing-l...@andreas-yeah I did the helper stuff. I didnt realize i could create a setup method and that would automatically run before the test methods. Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
def setup logger.info("\n\n STARTING #{get_method_name} \n\n") end gives me STARTING setup_without_fixtures in my log. If I put my logger in each method it prints fine. def test_account_create logger.info("\n\n STARTING #{get_method_name} \n\n") assert Account.create(:name => "Bob''s Tofu House", :short_name => "bths") end will print STARTING test_account_create any ideas why? -- 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 -~----------~----~----~----~------~----~------~--~---
I am assuming that the get_method_name just gets the name of the method that is currently running. In that case, since the logger statement in the setup methods, it will get that name which is not what you want. I don''t know of any way not to include something in each method. You can create an instance variable in each method and then pass it to the ''teardown'' method which runs after each method is run (setup runs before each method is run). I am not sure this will save you a lot of typing. You can also add to your get_method_name the logger but you sill have to call that method from each method. On Sep 10, 1:09 pm, Joel Saltzmanjoelh <rails-mailing-l...@andreas- s.net> wrote:> def setup > logger.info("\n\n STARTING #{get_method_name} \n\n") > end > > gives me > > STARTING setup_without_fixtures > > in my log. If I put my logger in each method it prints fine. > > def test_account_create > logger.info("\n\n STARTING #{get_method_name} \n\n") > assert Account.create(:name => "Bob''s Tofu House", :short_name => > "bths") > end > > will print > > STARTING test_account_create > > any ideas why? > -- > 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 -~----------~----~----~----~------~----~------~--~---