[rspec-users] Expecting nil or false

David Chelimsky dchelimsky at gmail.com
Tue Mar 31 17:35:07 EDT 2009


On Tue, Mar 31, 2009 at 12:54 PM, Fernando Perez <lists at ruby-forum.com> wrote:
>> What is the full expression? i.e. what is it that should be false (or
>> nil)?
>
> Basically:
>
> def is_it_cool?
>  find(blabla, :conditions => 'coolness > 1000')
> end
>
> In order to stay consistent and as the question mark suggests that true
> or false will be returned, I have updated my method too:
>
> def is_it_cool?
>  !!find(...)
> end
>
>
> Is true that the dynamic aspect of Ruby allows us to not have to
> statically type the return value of a method, so it could be an object,
> nil or a boolean.
>
> What do you think?

I don't know if you're familiar with the concept of truthiness, but
that is what you're talking about here. IMO, be_true should be
specific. I'm open to other opinions, and would consider changing the
way it works if we can do it without breaking everybody's stuff.

Somebody joked about having a be_truthy matcher. Perhaps he actually wrote one.

As for how I handle these things now, I would do this:

something.should be_cool

def cool?
  !!find(...)
end

I find that almost every time I approach it this way, I land on a
predicate method that is ruby-ish. is_it_cool? is not ruby-ish. nor
would is_cool?

FWIW,
David

> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list