Read more

Capybara: Trigger requests with custom request method

Dominik Schöler
September 03, 2013Software engineer at makandra GmbH

Preface: Normally, you would not need this in integrations tests (probably that's why it is so hard to achieve), because it is no actual "integration testing". If you use this step, know what you are doing.


Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Destroying a record with Capybara is not as easy as calling visit user_path(user, method: :delete), because RackTest's visit can only perform GET requests Show archive.org snapshot .

With this step you can destroy a records using either Selenium or RackTest. Example: When I destroy that user # => deletes User.last.

When /^I destroy that (.*)$/ do |element_type|
  element = element_type.classify.constantize.last
  path = "#{element_type}_path"

  case page.driver
  when Capybara::RackTest::Driver
    page.driver.submit :delete, send(path, element), {}
  else # e.g. Capybara::Selenium::Driver
    visit send(path, element, { method: :delete })
  end
end
Posted by Dominik Schöler to makandra dev (2013-09-03 17:48)