[rspec-users] Re-using Rspec Matchers

Ben Mabey ben at benmabey.com
Wed Sep 8 17:26:41 EDT 2010


  On 9/8/10 11:42 AM, Brian Kaney wrote:
> Hey Everyone,
>
> Is it good practice to call matchers from within matchers?   Kinda like this pattern:
>
>    See: http://gist.github.com/570467
>
No, that should be avoided.  The problem is that the "internal" matcher 
will throw an exception that will bubble up and be reported.  Meaning 
that the parent matcher (link_one in your case) is not reported and the 
resulting stacktrace can be confusing.  Try something like this:

include_association(expected).matches?(actual) && 
associate_one(expected).matches?(actual)

(Note, I have not tried the above but I think it should work.)

-Ben


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100908/2f9fce0e/attachment.html>


More information about the rspec-users mailing list