L-exp Mobile

Redefine the run method of Test::Unit::TestCase

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

It is not only for Rails but for Ruby. In Rails you can redefine it at the beginning of your test_helper.rb for example.



Options:   Save This | Share
Viewed 0 times
Published 3 months ago
By
From Resource Inwebwetrust : Fernando Blat in lists:
Conferencia Rails Hispana '07

Menu

by Genís