我经常遇到水豚问题与请求测试失败,因为水豚没有等待ajax事件完成前继续前进。水豚ajax竞争条件
谷歌似乎表明我应该使用:resynchronize选项为我的测试来解决这个问题。但它不起作用。
为了证明这是一个问题,可以通过在ajax调用之后放置sleep语句来修复失败的测试。这看起来很糟糕,因为适当的延迟会根据运行测试的机器的速度而变化。选择一个合适的大值会严重减慢运行一个包含大量Ajax操作的测试套件。
一个失败/通过测试的例子如下。点击保存之前的睡眠,使路过的区别/上page.should have_content失败(“自定义项目”):
it "should be able create a new todo item", :js, :resynchronize, :focus do
# Visit new action
visit new_todo_list
# Fill in the name
fill_in "#name", "test list"
# Click on add item to launch inline popup
find('a.add-item').click
within '#new_item' do
fill_in 'todo_item_description', :with => 'custom item'
# Run ajax action to add currrent item
find('.btn').click
end
sleep(1)
# Save
find('a.save').click
page.should have_content('test list')
page.should have_content('custom item')
end
这是水豚的错误还是我做错了什么?
感谢您的帮助......
谢谢,这是不是任意的睡眠好多了! – Chris 2012-08-02 13:13:36