Using Capybara to select from a collection_select call (select tag)

137 views
Skip to first unread message

David Zhang

unread,
Jul 5, 2011, 7:34:52 PM7/5/11
to rubyonra...@googlegroups.com


I'm trying to use Capybara to test this.  I have a step that goes


    When I select "Price Chopper" from "Organization"


And the step definition is 


When /^(?:|I )select "(.+)" from "(.+)"$/ do |value, field|

  select(value, :from => field)

end


For some reason, I keep getting the error:


cannot select option, no select box with id, name, or label 'Organization' found (Capybara::ElementNotFound)

      (eval):2:in `select'


… although my view is


<label>Organization</label>

<%= collection_select :restaurant, :organization_id, Organization.all, :id, :name, { :prompt => "[Select organization]" } %>



Shouldn't this work?  The label is "Organization"!

David Zhang

unread,
Jul 9, 2011, 10:06:43 PM7/9/11
to rubyonra...@googlegroups.com
I'm sure the solution to this is simple... anyone know?  I just want to test the select field...

jrw

unread,
Jul 12, 2011, 5:19:33 AM7/12/11
to rubyonra...@googlegroups.com
The error message is "no select box ... with label 'Organization' found". Your label exists, but it is not connected to the select field.
It should be <label for="restaurant_organization_id"></label>
If you're using it in some kind of form_for(@restaurant) - helper you'd simply have to use form.label :organization_id.
Reply all
Reply to author
Forward
0 new messages