[rspec-users] Can I do foo.should (be_nil || be_empty) in rspec

Pat Maddox
2008-11-04T15:29:40Z

"Andrew Premdas" <apremdas at gmail.com> writes:

> General case I''m thinking about is just testing that something
should be one thing or another
>
>    e.g x.should be(foo || bar)
>
> Haven''t got a specific example at the moment apart from the blank
one.  What I''m thinking about is the syntax to say this in a spec, as I
> think there must be lots of times when having this sort of syntax would be
useful.

Hi,

This is a case where a custom matcher would be hiding a concept that
belongs directly in your code.  If you really don''t care about the
difference between empty and nil, you should create a method - such as
#blank? - that handles that for you.

Pat