A small snippet for testing.
If you want to add some special actions before and after the execution of each test, and don't want to add it to setup and teardown because you will be repeating your code for each unit test and functional test, or because it is a block, you can do an alias_method_chain for the run method:
module Test module Unit class TestCase def run_with_my_block(*args, &block) Cache.clean # code before a_block_that_you_want_to_execute do run_without_my_block(*args, &block) end # Code after end alias_method_chain :run, :my_block end end end
You can redefine it at the beginning of your test_helper.rb for example.
Note that this code is only for Rails, becaus of the use of alias_method_chain function.

Nice tip! Just a comment: I think that alias_method_chain is defined in Rails so it should be included somehow to use this tip on non-Rails code.
Yes, you are right. I'll change that part of the ost.