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

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)


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


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

Shouldn’t this work? The label is “Organization”!

I’m sure the solution to this is simple… anyone know? I just want to test the select field…

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

If you’re using it in some kind of form_for(@restaurant) - helper you’d simply have to use form.label :organization_id.