How to make Capybara do a DELETE request in a Cucumber feature?

umar picture umar · Feb 10, 2012 · Viewed 8.2k times · Source

I am using Cucumber and Capybara. I need to make an HTTP DELETE request. Previously the features used webrat, so a simple statement like

visit "/comment/" + comment_id, :delete

worked, but now I am using Capybara.

The way to do a GET request is simply:

get 'path'

And to do a post request:

page.driver.post 'path'

But how can I simulate a DELETE request?

I found out that the driver Capybara is using is Capybara::RackTest::Driver, if that is any help.

I have also tried:

Capybara.current_session.driver.delete "/comments/" + comment_id

But that does not work.

Answer

1000 Needles picture 1000 Needles · Jul 23, 2012
page.driver.submit :delete, "/comments/#{comment_id}", {}

Documentation at: http://rubydoc.info/gems/capybara/1.1.2/Capybara/RackTest/Browser:submit