Rails 3 and rspec - select from select list

心已入冬 提交于 2019-12-22 05:11:35

问题


I want to select value from select list in RSpec. For example i have such data:

<div class="control-group">
 <label class="control-label" for="user_teacher_leader_attributes_teacher_id">Teacher names</label>
  <div class="controls">
   <select id="user_teacher_leader_attributes_teacher_id" name="user[teacher_leader_attributes][teacher_id]">
    <option value="1" selected="selected">Math teacher</option>
    <option value="2">Physics teacher</option>       
  </div>
</div>

I want to select option Physics teacher via RSpec. How can i do that? Also, can i choose something from the list by value (for example, select Physics teacher by value "2" which it has)?


回答1:


I found solution. You should use select method:

select "Physics teacher", :from => "teacher_leader[teacher_id]"


来源:https://stackoverflow.com/questions/10055561/rails-3-and-rspec-select-from-select-list

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