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

David Chelimsky dchelimsky at gmail.com
Tue Nov 4 14:26:35 EST 2008


On Tue, Nov 4, 2008 at 1: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?

If you can do it w/o breaking existing behaviour, sure.

Alternatively, you could add a new method:

def_matcher

or something like that.

Either way, it would be totally worth it.

>
> Ashley
>
> --
> http://www.patchspace.co.uk/
> http://aviewfromafar.net/
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list