Ruby-on-rails – How to make Capybara do a DELETE request in a Cucumber feature

capybaracucumberintegration-testingruby-on-rails

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.

Best Answer

page.driver.submit :delete, "/comments/#{comment_id}", {}

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