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
Advertisements

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s