6

我想从RSpec的选择列表中选择值。例如我有这样的数据:

<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>

我想Physics teacher通过RSpec选择选项。我怎样才能做到这一点?另外,我可以按值从列表中选择一些东西(例如,Physics teacher按它具有的值“2”选择)吗?

4

1 回答 1

17

我找到了解决方案。您应该使用select方法:

select "Physics teacher", :from => "teacher_leader[teacher_id]"
于 2012-04-07T16:46:35.323 回答