Ruby 1.8.7-compat way to undef test classes

add cleanup after each definition

This is yet another tweak needed for #2625 to pass.