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??
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??
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
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.
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!
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?
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.