Preventing Capybara from following :method => :delete links
My project is using Rails 3 and RSpec and Capybara for testing.
I want to support visitors without javascript, so I've added a 'delete' member to my resource routes. My non-js links look like /posts/3/delete. These then present a form to the user which then does a post request to the destroy action. I'm using extra javascript to strip off the /delete so that the links still work correctly for those who have it turned on.
The problem I've run in to, is that Capybara wants to follow the /posts/3/delete links using an HTTP DELETE request, but it doesn't support the javascript which strips off the /delete. Is there a way I can tell Capybara to just follow all link开发者_StackOverflow中文版s with HTTP GET?
While it is not an option you can simply turn on or off yet, this patch is how I ended up solving this for now.
class Capybara::RackTest::Driver < Capybara::Driver::Base
class Capybara::RackTest::Node < Capybara::Driver::Node
def click
if tag_name == 'a'
driver.follow(:get, self[:href].to_s)
elsif (tag_name == 'input' and %w(submit image).include?(type)) or
((tag_name == 'button') and type.nil? or type == "submit")
Capybara::RackTest::Form.new(driver, form).submit(self)
end
end
end
end
Edit: It appears that this will be changed to work this way in version 2. https://github.com/jnicklas/capybara/issues/184#issuecomment-1940520
精彩评论