New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow #must_be and #wont_be to test truthiness / falsiness #58
Comments
I'd rather not overload |
That sounds reasonable. |
Honestly, I still have misgivings about this issue. The number of plain There just isn't much value in saying "this should not be one of two values out of the infinite range of values possible"... Instead, you should test that you actually know what it is. For all you know you get an array back when you think it should be a number... By testing just truthiness, you get very little value (or security) out of your tests. |
I can understand that. The case where I find it useful to test truthiness is when a method's documentation states that its return value indicates whether some condition is true, without saying that it specifically returns That's the pragmatic argument, and the one that matters to me. The purist argument would be: there should be parity between the test API and the spec API. |
Did you know that |
@sunaku, that's a good point. Assert is available and really... I don't really see the added value of this. Esp if the justification is to test some other library's ill-defined response. I think I'm going to bury this. |
What about just #must? File.exists?('/etc/passwd').must Kind of weird, in a Louis CK way. But must and wont are sufficient for truthy/falsy. Just throwing it out there. |
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
orfalse
.Instead of this:
It would be nice to do this:
I.e., use MiniTest::Spec to test Ruby's idiomatic Boolean logic where
nil
andfalse
are falsy and everything else is truthy. I can already do this with MiniTest::Unit:Note: at first I considered adding
Object#truthy?
andObject#falsy?
methods and usingmust_be :truthy?
etc. But I think the 0-argmust_be
andwont_be
methods are nicer in two ways: they don't add methods toObject
and they are slightly more concise.(And no, I didn't get this idea from RSpec. :-)
The text was updated successfully, but these errors were encountered: