Custom Macros/Matchers

23 views
Skip to first unread message

Amol Hatwár

unread,
Jul 28, 2010, 9:43:45 PM7/28/10
to shoulda
Hello,

I noticed with the new shoulda releases custom macros no longer work. This is probably because of the matcher direction that shoulda is taking whilst deprecating macros...

Now, back in the day writing custom macros was fairly easy. As of today, I haven't been able to spot a single resource on how to do custom matchers in shoulda. Is it supported? And are there any tips to get started?

Cheers,

Amol


Dan Croak

unread,
Aug 4, 2010, 1:06:09 PM8/4/10
to sho...@googlegroups.com
Amol,

That's a reasonable question. In RSpec, you write custom matchers like this:

http://wiki.github.com/dchelimsky/rspec/custom-matchers

You're asking specifically about Test::Unit, however?

A good example might be the validate_presence_of matcher from the
Shoulda source:

http://github.com/thoughtbot/shoulda/blob/master/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb

You'll see they can be very straightforward. If you'd like more
information, I can try to write up a blog post about it and link to it
from the Shoulda docs.

Dan

> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Shoulda group:
> http://groups.google.com/group/shoulda
>
> To post to this group, send email to
> sho...@googlegroups.com
>
> To unsubscribe from this group, send email to
> shoulda+u...@googlegroups.com
>

Daniel

unread,
Aug 9, 2010, 12:47:32 PM8/9/10
to shoulda
That would be enormously helpful for me, at least. I found several
articles from 2008 and 2009 that described how to write custom macros
for shoulda, but the macros I wrote don't appear to work, and I have
no idea whether it's because I'm doing something wrong or because
shoulda is moving to the use of matchers instead of macros. Some kind
of documentation describing the correct way of doing things would be
great.

On Aug 4, 1:06 pm, Dan Croak <dcr...@thoughtbot.com> wrote:
> Amol,
>
> That's a reasonable question. In RSpec, you write custom matchers like this:
>
> http://wiki.github.com/dchelimsky/rspec/custom-matchers
>
> You're asking specifically about Test::Unit, however?
>
> A good example might be the validate_presence_of matcher from the
> Shoulda source:
>
> http://github.com/thoughtbot/shoulda/blob/master/lib/shoulda/active_r...
Reply all
Reply to author
Forward
0 new messages