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

Ashley Moran ashley.moran at patchspace.co.uk
Tue Nov 4 06:23:03 EST 2008

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.)



More information about the rspec-users mailing list