seattlerb/minitest — Issue #58: Allow #must_be and #wont_be to test truthiness / falsiness
Author: BMorearty
Created: 2011-10-11 06:01:21+00:00
State: open

I appreciate issue #31. Along those lines it would be nice to be able to test truthiness and falsiness without comparing a result to `true` or `false`.

Instead of this:

some_obj.truthy_method.must_equal true
some_obj.falsy_method.must_equal false

It would be nice to do this:

some_obj.truthy_method.must_be
some_obj.falsy_method.wont_be

I.e., use MiniTest::Spec to test Ruby's idiomatic Boolean logic where `nil` and `false` are falsy and everything else is truthy. I can already do this with MiniTest::Unit:

assert(some_obj.truthy_method)
refute(some_obj.falsy_method)

Note: at first I considered adding `Object#truthy?` and `Object#falsy?` methods and using `must_be :truthy?` etc. But I think the 0-arg `must_be` and `wont_be` methods are nicer in two ways: they don't add methods to `Object` and they are slightly more concise.

(And no, I didn't get this idea from RSpec. :-)