[rspec-users] Problem with Custom matcher and Blocks

Brandon Olivares programmer2188 at gmail.com
Thu Apr 2 19:04:28 EDT 2009



> -----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 6:04 PM
> To: rspec-users
> Subject: Re: [rspec-users] Problem with Custom matcher and Blocks
> 
> 
> 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
> instance?

Oh OK. Well what I want is to be able to test if that form exists on the
page.

So how would you recommend going about it otherwise? I tried putting a begin
... end block around it, but that doesn't seem to work either.

    def matches? response, &block
      @block ||= block
      begin
        response.should have_selector('form#%s' % [@id]) do |form|
          !@block or @block.call form
        end
      rescue
        false
      else
        true
      end
    end

It still has an error, but now it's covered up by my failure_message. I
output $! As a test, though, and it's the same error.

Brandon




More information about the rspec-users mailing list