【发布时间】:2012-10-19 03:27:00
【问题描述】:
我正在尝试使用 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>
【问题讨论】:
-
我用 select user.name 代替,它通过了。显然 other_user 没有被创建?我正在使用 FactoryGirl 音序器。
-
你可以使用
let!来避免懒惰评估
标签: ruby-on-rails testing rspec-rails