Monthly Archives: October 2010

Find Duplicate Ruby Tests

In ruby, if you define a function twice in one class, the second definition overrides the first. This is really tricky if you accidentally use the same test name twice.

Here’s a quick one liner to find any duplicated method definitions in your file:

grep test/**/*_test.rb -e 'def ' | uniq -c | awk '$1 > 1'

If you have any duplicates, you will see something like this:

2 user_controller_test.rb: def test_updating_user
3 cake_controller_test.rb: def test_applying_frosting

Now go and get those tests fixed up!

Leave a comment

Filed under Uncategorized