I have Ruby 2.0 code that operates on phone numbers, which I want to test using MiniTest. I have a function which takes a phone number arguments and tests it (including asserts). Each time I call that function, I want it to be a new test case. Something like this:
listOfPhoneNumbersForTesting.each { |phone| testphone phone }
What I DO NOT want is this:
class test2125551212 < MiniTest::Unit::TestCase
def t2125551212
testphone "2125551212"
end
end
... repeated 10, 20, or 100 times to test each phone number ...
Obviously, I could put the loop code within a MiniTest::Unit::TestCase, but that results in just one testcase no matter how many phone numbers I test, and I don't like that. (Also, if one of the asserts fail, then no more phone numbers are tested, and I don't want that!) Also the second form looks like a violation of DRY to me, since the class name, function name, and argument all contain the phone number.
Somehow I feel that I should be able to have one class called TestPhone, and create it with the phone number argument, and get that into the MiniTest framework. but I would be willing to use setup(), Fixtures, metaprogramming, or just about anything else, if it would work.
listOfPhoneNumbersForTesting.each { |phone| TestPhone.new phone }
Where TestPhone is a TestCase subclass, and ends up calling testphone to do the work.
Basically, what I want is this: 1. One list of phone numbers, and if I add a number to the list, I get one more TestCase in reporting output. 2. If the tests associated with one phone number fail, the rest are still tested. 3. All phone numbers get the same testing, which includes several assertions.
Thanks very much!