# Avoiding Copy errors in Test::Unit (PATCH to Test::Unit::TestCase)

**URL:** <https://www.ruby-forum.com/t/avoiding-copy-errors-in-test-unit-patch-to-test-testcase/126474>\
**Category:** Ruby\
**Created:** [January 18, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/avoiding-copy-errors-in-test-unit-patch-to-test-testcase/126474 "2008-01-18T16:18:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RSBernstein](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@RSBernstein](https://www.ruby-forum.com/u/RSBernstein)\
**Post date:** [January 18, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/avoiding-copy-errors-in-test-unit-patch-to-test-testcase/126474/1 "2008-01-18T16:18:30Z")

</div>

I use Test::Unit a lot, and a lot of the times I create a new test by  
taking an old test, copy that to a new file and start modifying  
it. The problem is that I sometimes forget to change the class name.

When this happens, tests still work but one class of tests has  
silently been discarded.

A colleague, Martin Davis, came up with this simple, short monkeypatch  
to hook onto method\_added to check for this condition. It works very  
well. I think this would be a great addition to Test::Unit::TestCase  
in test/unit/testcase.rb

Until then, here’s a little file you can load/require:

---

<div class="post-metadata">

**Author:** ![RSBernstein](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@RSBernstein](https://www.ruby-forum.com/u/RSBernstein)\
**Post date:** [January 18, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/avoiding-copy-errors-in-test-unit-patch-to-test-testcase/126474/2 "2008-01-18T16:43:32Z")

</div>

On Jan 18, 8:14 am, “R. Bernstein” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in test/unit/testcase.rb
> 
> Until then, here’s a little file you can load/require:
> 
> test\_helper.rb

I like it. However, I should point out that you’ll already get a  
warning about redefined methods if you have a setup or teardown method  
in any dup’d classes. That’s assuming you’re running your tests with -  
w, which of course you are. 🙂

Still, I think it’s a worthy addition.

Regards,

Dan
