test that yield is given number of seconds#6
Conversation
|
This looks good to me but I feel a little bit odd about using a string. But it also works pretty well… what do you think? |
|
My goal was to do something "realistic" which does something with the value, to test that the return value is what the block returns and also that the block has access to the param. If we don't use a string, what alternative do you have in mind? one of these? assert_equal 5, Timeout.timeout(5){|s| s }
assert_equal 6, Timeout.timeout(5){|s| s+1 } |
|
I would say there are two tests:
The biggest issue I see with the string formatting is time precision, but as long as we use an integer, it would be okay? But I'm not sure we can guarantee the value of the timeout argument? In the future we might want a more precise measurement of time than just the numeric value. |
|
ah, so you are saying that involving the string interpolation makes the test brittle, because one day the code might, say, run to_f on s, and then the string will be "5.0 seconds" and the test will erroneously break? what do you think of one of these? assert_equal 5, Timeout.timeout(5){|s| s }
assert_equal 6, Timeout.timeout(5){|s| s+1 }
assert_equal [5, :ok], Timeout.timeout(5){|s| [s, :ok] }
x = rand(1..10); assert_equal x, Timeout.timeout(x){|s| s }although... those might all have the same problem... depending on if the test environment does a flexible equals |
|
I think as long as we consider the issue, I'm fine with whatever you ultimately propose. |
e7b232a to
939a9f5
Compare
|
Okay, I went with the array |
|
|
939a9f5 to
d62d22d
Compare
Nothing currently covers this behavior