[rspec-users] Problem with Custom matcher and Blocks

Brandon Olivares programmer2188 at gmail.com
Thu Apr 2 17:56:27 EDT 2009

Hi again,

Well, I looked in the Webrat matchers code, and saw they also have a block
argument to the matches? Method, though I don't know why. So I copied what
they did there, and got a bit more informative output. Unfortunately now I
have more errors.

Before I continue, do you know why I have to include &block as the second
argument to `matches?'?

So now it won't recognize my subject field. The error is something like

'/contact/index the contact form before it has been submitted the subject
dropdown box should have a feedback option' FAILED
expected following output to contain a <select[id=subject]/> tag:
<form action="/contact.html" id="contact" method="post">
    <label for="subject">Subject</label>
    <select id="subject" name="subject"><option value=""></option>
<option value="feedback">Feedback</option>
<option value="questions">Questions</option>
<option value="suggestions">Suggestions</option>
<option value="other">Other</option></select>
ve_a_form_with_id.rb:16:in `call'
ve_a_form_with_id.rb:16:in `matches?'
core/matchers/have_xpath.rb:21:in `call'
core/matchers/have_xpath.rb:21:in `matches?'
ve_a_form_with_id.rb:15:in `matches?'

That example is something like:

        it "should have a feedback option" do
          response.should have_a_contact_form do |form|
            form.should have_selector('select', :id => 'subject') do
              subject.should have_selector('option', :content => 'Feedback')
        end # it "should have a feedback option"

Thanks for any help.


More information about the rspec-users mailing list