I am writing a test helper and it has this method:
def todo msg = ''
assert false, '@TODO: ' + msg
end
Basically I want a quick method to fail a test. Next, I would like to test this method (because it will be encapsulated in a shippable helper). So I would like to write something like this:
test 'todo' do
result = todo
expected = '@TODO: '
assert_equal expected, result
end
but it just fails when assert false gets called. So, how would I test this method?
This helper is supposed to work with
Test::Unit, is that right? I believe thatassert falsethrows an exception which is caught byTest::Unit. You could just wrap the call totodoin abegin...rescueblock and catch that exception.The
test/unitwhich comes in the Ruby standard libraries is actuallyMinitest::Unit— when an assertion fails, it raises aMinitest::Assertionexception. You couldrescuethat.For the “real”
Test::Unit, it raises aTest::Unit::AssertionFailedErrorwhen an assertion fails.