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']
    end

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

Leave a comment