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

Ashley Moran
2008-11-04T11:23:03Z

On 4 Nov 2008, at 11:10, Andrew Premdas wrote:

> Is there any way to do
>
>   foo.should (be_nil || be_empty)
>
> in rspec.

That won''t do what you want it to, at first glance it will always
match with be_nil.  You could write a custom matcher
(be_nil_or_empty), but I suspect that''s not the real answer here.

Why do you want to do this?  What is the distinction between nil and
empty in your app?  I suspect this is a data modelling issue rather
than a spec issue.  (Be very wary as soon as you see conditionals in
your code.)

Ashley


--