我正在尝试使用 rspec 来测试从 select 标记中选择一个值。select 标记应列出数据库中每个用户的所有名称。当我浏览该站点时,它可以工作。但测试似乎没有看到 FactoryGirl 创建的用户名:
错误是:
cannot select option, no option with text 'Person 4' in select box 'receiver_id'
这是 message_pages 规范的一部分:
let(:user) { FactoryGirl.create(:user) }
let(:other_user) { FactoryGirl.create(:user) }
before do
select other_user.name, :from => 'message[receiver_id]'
fill_in "Subject", with: "Hello"
fill_in "Body", with: "It's time to have fun!"
end
这是我的视图的 HTML 输出:
<label for="message_receiver_id">Receiver</label>
<select id="message_receiver_id" name="message[receiver_id]"><optionvalue="12">John</option>
<option value="13">Tom</option>
<option value="9">Jay</option>
<option value="14">Bob</option></select>