I was wondering if there is a way to pass arguments to individual tests in rails similar, or similar in idea, to NUnit's TestCase Attribute. Thanx
+1
A:
The way you do parameterized tests in Ruby (and Python) is to dynamically create the test methods:
[[12, 3, 4], [12, 2, 6], [12, 4, 3]].each do |n, d, q|
test "#{q} is the quotient of #{n} and #{d}" do
assert_equal q, n/d
end
end
Make certain that the test names include the data.
Kathy Van Stone
2009-09-28 15:45:20
Won't n, d, and q be arrays variables and not numbers?
Chris C
2009-10-01 18:54:14
Each element of the main array is an array of 3 items. when you split the arguments into |n, d, q| they are assigned to each element of that 3 item array. Thus the first round they will be n = 12, d = 3, q = 4, and the second time they will be n = 12, d = 2, q = 6, etc.
Kathy Van Stone
2009-10-01 20:34:13
I understand now. Thank you.
Chris C
2009-10-05 19:45:16