[rspec-users] Problem with Custom matcher and Blocks

Matt Wynne matt at mattwynne.net
Thu Apr 2 18:03:36 EDT 2009

On 2 Apr 2009, at 22:20, Brandon Olivares wrote:

> Hi,
>> -----Original Message-----
>> From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-
>> bounces at rubyforge.org] On Behalf Of Matt Wynne
>> Sent: Thursday, April 02, 2009 3:55 PM
>> To: rspec-users
>> Subject: Re: [rspec-users] Problem with Custom matcher and Blocks
>> #have_selector is part of webrat. Have you required the appropriate
>> files so that method is visible to your new matcher class?
> Oops, forgot that.
> OK, so I added:
> Require 'webrat/core/matchers/have_selector'
> On the first line, and directly within the class:
> Include Webrat::Matchers
> Is this correct?

Think so. Did the error go away?

> OK, so now all 16 examples pass. But one of them should be failing  
> -- the
> one with the name. Do you see any reason that is still passing?
> Again my matches? Method is as follows:
>    def matches? response
>      response.should have_selector('form#%s' % [@id]) do |form|
>        !@block or @block.call form
>      end
>    end

I don't think you want to be using #should here. If that fails it will  
raise an exception but the expected behaviour of a matcher is to  
return true / false from #matches? so that will be one problem you  
have. Try just hard-coding the #matches? method to return false and  
see if you get one of your tests to fail.

What are you imagining that #response is going to return in this  

Matt Wynne

More information about the rspec-users mailing list