Search code examples
ruby-on-railsrspectwitter-bootstrapformtastic

Twitter bootstrap-formtastic failing rspec test after adding dropdown list


I have a bootstrap formtastic form which was passing all of my rspec tests.

Until I change one of the fields from a normal text_field to a drop-down list

<%= f.input :gender, :label => "Gender" %>

to

<%= f.input :gender, 
:label => "Gender",
:collection => [["Female", "F"], ["Male", "M"]] 
%>

then I get the following error message:

Failure/Error: fill_in "Gender", with: "F"
Capybara::ElementNotFound: cannot fill in, no text field, text area or password field with id, name, or label 'Gender' found.

RSpec seem to be complaining the following line:

before do
    fill_in "Gender", with: "F"
    ...

Did I do something wrong? Coding, Configuration, Everything? Can someone please help?


Solution

  • As klump says you should use the proper method to select the value.

    Since you are using Capybara that is select "F", :from => "Gender"

    You can find more info in the Capybara API