Test::Unit Rails - How to assert one number is greater than another one?

Amokrane Chentir picture Amokrane Chentir · Apr 28, 2011 · Viewed 13k times · Source

I am writing my first unit tests with Test::Unit and I have reached a point where I need to compare two numbers. Much to my surprise, I have discovered that none of the following were available:

assert_greater_than
assert_lesser_than
assert_greater_or_equal_than
assert_lesser_or_equal_than

Is this normal? How should I do it then?

Thanks

Answer

Jacob Mattison picture Jacob Mattison · Apr 28, 2011

Rather than provide a bunch of different assertions as you suggest, Test::Unit provides the method assert_operator, used like this:

assert_operator x, :>, y
assert_operator x, :>=, y
etc.