views:

80

answers:

1

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
Won't n, d, and q be arrays variables and not numbers?
Chris C
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
I understand now. Thank you.
Chris C