[rspec-users] Custom matcher for predicates

Ed Howland ed.howland at gmail.com
Sat Dec 26 23:29:47 EST 2009


On Sat, Dec 26, 2009 at 7:56 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
> On Sat, Dec 26, 2009 at 6:55 PM, David Chelimsky <dchelimsky at gmail.com>
> wrote:
>>
>> On Sat, Dec 26, 2009 at 5:53 PM, Ed Howland <ed.howland at gmail.com> wrote:
>>>
>>> I hope this isn't a dumb question, but can a custom matcher be written
>>> for a possibly non-existant predicate? I know that if the object
>>> responds to some predicate? message, RSpec will breate a custom
>>> matcher on the fly for it. Such as be_naughty or be_nice for
>>> sarah.naughty? and jane.nice?
>>
>> It's not that RSpec looks at your code and creates predicates for it. When
>> you say "jane.should be_nice", RSpec looks to see if jane has a nice?()
>> method and uses that if it's there. Subtle, but important difference.
>
> I should add here, that if you've already defined a be_nice method, it will
> be called. RSpec only checks for a predicate when it gets method_missing,
> which it wouldn't if you've defined a method already.
> HTH,
> David

Thanks, David.

That helps my understanding a lot.

Happy Boxing day, or what's left of it

Ed


>



-- 
Ed Howland
http://greenprogrammer.wordpress.com
http://twitter.com/ed_howland


More information about the rspec-users mailing list