Reputation: 45943
How to get the action of a form in Capybara?
I know it is not proper BDD, but the form is hitting an API outside of the app.
Checking that the form is submitted can be done with Webmock, but in this case I think it is simpler to make sure the action URL is set properly.
Upvotes: 3
Views: 2251
Reputation: 3260
I'm pretty sure capybara
(at least version 2.1.0) has helpers to make this easier.
In our specs, we check form actions like this:
form_action = find('#form_id')['action']
So you don't need to get the Nokogiri native element.
Upvotes: 8
Reputation: 6034
You can retrieve the Nokogiri node from a Capybara element with .native, from there you can easily query the node's attributes:
element = find('#form_id')
node = element.native
form_action = node.attributes['action']
Upvotes: 2