水豚和Rspec:如何删除帐号? [英] Capybara & Rspec: How to delete an account?
本文介绍了水豚和Rspec:如何删除帐号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Devise并为用户删除自己的帐户编写一个测试,但是我坚持如何调用确认框,然后单击确定。
I'm using Devise and writing a test for the scenario of a user deleting their own account but I'm stuck on how I would call up the confirm box and click OK.
这是链接和测试:
<p><%= link_to "Delete my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
spec / requests / users_spec.rb
spec/requests/users_spec.rb
scenario 'user deletes account' do
make_user_and_login
click_link('Account Settings')
page.should have_selector('title', :text => 'Account Settings')
click_link('Delete my account')
# Are You Sure?
# click OK in confirm box
# page.should etc.....
end
如何做?
推荐答案
确保capybara正在使用支持javascript的驱动程序。
然后尝试这样:
Make sure capybara is using a driver which supports javascript. Then try this:
page.driver.browser.switch_to.alert.accept
另外,要取消:
page.driver.browser.switch_to.alert.dismiss
这篇关于水豚和Rspec:如何删除帐号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文