Selecting a radio button with Rspec

匿名 (未验证) 提交于 2019-12-03 08:39:56

问题:

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 

回答1:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!