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

Zach Dennis zach.dennis at gmail.com
Tue Nov 4 14:24:57 EST 2008


On Tue, Nov 4, 2008 at 2:14 PM, Ashley Moran
<ashley.moran at patchspace.co.uk> wrote:
>
> On Nov 04, 2008, at 5:07 pm, David Chelimsky wrote:
>
>> FYI - if you REALLY want to match against either, it's pretty easy to
>> do w/ simple matcher:
>>
>> def be_nil_or_empty
>>  simple_matcher "nil? or empty? to return true" do |actual|
>>   actual.nil? || actual.empty?
>>  end
>> end
>
>
> Wow, I completely forgot about simple_matcher.  That REALLY deserves a more
> prominent place in the docs!  It's a great feature.
>
> Would be really cool if you could do it like this though:
>
>  simple_matcher :be_nil_or_empty, "nil? or empty? to return true" do
> |actual|
>   actual.nil? || actual.empty?
>  end
>
> and have it call define_method for you.
>
> That's one I could hopefully do myself in time, after I've got a few
> Merb/DataMapper jobs out of the way.
>
> WYDAT?  Worth filing a ticket for?

There are a few obstacles that it would have to overcome. As-is I
don't think that will work. If you file a ticket I'll comment there as
to why I think that. :)


-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list