Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a radio button with Rspec

I'm currently writing a test for a form using RSpec, and I was wondering how I'd go about selecting a radio button, given the form below:

<%=form_for(@whatever) do|f|%>

         <%=f.label :option, "TRUE" %>
         <%=f.radio_button :option, true %>
         <%=f.label :option, "FALSE" %>
         <%=f.radio_button :morning, false %>

         <%=f.submit "SAVE" %>
      <% end %>

I want my test to look something like:

       describe "with valid options selected" do

          before do
            #CODE TO SELECT A RADIO BUTTON
            click_button "SAVE"
          end

        end
like image 834
TangoKilo Avatar asked Jul 14 '12 13:07

TangoKilo


1 Answers

describe "with valid info" do    
  before do 
   choose('True')
   click_button "Create Setlist"
  end
  ...
end

I had to assign an ID to the radio button for this to work as well

Doc for additional reference: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions

like image 113
TangoKilo Avatar answered Sep 27 '22 21:09

TangoKilo