Click Rails UJS / data-method links in Capybara without using a browser

Not using a browser is a lot faster, so let’s try to avoid it if possible.

click_ujs_link "Delete"
click_ujs_link "Post"


    def click_ujs_link(name)
      link = find(:link, name, {})
      visit_with_method link['data-method'], link['href']

    def visit_with_method(method, url)
      page.driver.send method, url
      visit page.driver.response.location

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s