我在一个演示应用中发现了这一点:
it "should be able to use bip_text to update a text field" do
@user.save!
visit user_path(@user)
within("#email") do
page.should have_content("lucianapoli@gmail.com")
end
bip_text @user, :email, "new@email.com"
visit user_path(@user)
within("#email") do
page.should have_content("new@email.com")
end
endhttps://github.com/dougc84/best_in_place/blob/master/spec/integration/js_spec.rb
看起来很简单。
所以我把它复制到我的Capybara规范中:
before (:each) do
@report = FactoryGirl.create(:report)
visit report_path(@report)
end
it "name", :focus do
within("#name") do
page.should have_content @report.name
end
bip_text @report, :name, "new name"
visit report_path(@report)
within("#name") do
page.should have_content "new name"
end
end 它的速度如此之快,我几乎看不到任何东西,但它看起来确实与#name字段有关。然后页面重新加载,它仍然是旧值。
有什么帮助吗?
哦,顺便说一句,它确实可以在浏览器中工作。就是不能让测试通过。
发布于 2013-11-09 23:10:20
我在bip_助手之前和之后添加了sleep 1,它起作用了。
发布于 2014-01-24 12:56:29
这里的问题是由bip_text运行的Javascript是异步的,但在您的下一行中,您会立即转到另一个页面,使Javascript永远无法完成。这就是你的sleep 1修复它的原因。你也可以通过让Capybara在visit report_path之前等待一些新的内容来修复它,但是然后你需要向页面写一些类似成功的消息(例如,使用ajax:success JS回调)。
https://stackoverflow.com/questions/19877371
复制相似问题