Capybara & Rspec: How to delete an account?

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.

Here is the link and my test:

<p><%= link_to "Delete my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>

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

How would this be done?

Answers


Make sure capybara is using a driver which supports javascript. Then try this:

page.driver.browser.switch_to.alert.accept

Alternately, to cancel:

page.driver.browser.switch_to.alert.dismiss

Need Your Help

How to determine Content Type of a HTTP Servlet Request?

json servlets httprequest content-type http-request

How can I get the content type from the HttpServletRequest without reading the request body?

Facebook crawler?

facebook social-networking web-crawler

I'm a graduate student whose research is complex network. I am working on a project that involves analyzing connections between Facebook users. Is it possible to write a crawler for Facebook based on

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.