[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
this:

'/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">
  <div>
    <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>
</div>
</form>
./spec/views/contact/index.html.erb_spec.rb:39:
/home/Brandon/projects/bartenders-to-go/spec/views/matchers/form_matchers/ha
ve_a_form_with_id.rb:16:in `call'
/home/Brandon/projects/bartenders-to-go/spec/views/matchers/form_matchers/ha
ve_a_form_with_id.rb:16:in `matches?'
/home/Brandon/projects/bartenders-to-go/vendor/gems/webrat-0.4.3/lib/webrat/
core/matchers/have_xpath.rb:21:in `call'
/home/Brandon/projects/bartenders-to-go/vendor/gems/webrat-0.4.3/lib/webrat/
core/matchers/have_xpath.rb:21:in `matches?'
/home/Brandon/projects/bartenders-to-go/spec/views/matchers/form_matchers/ha
ve_a_form_with_id.rb:15:in `matches?'
./spec/views/contact/index.html.erb_spec.rb:38:

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|
              subject.should have_selector('option', :content => 'Feedback')
            end
          end
        end # it "should have a feedback option"

Thanks for any help.

Brandon




More information about the rspec-users mailing list