With Rails, rspec and capybara, I'm trying to test your typical ERB generated form:
<form action="/pages/1" id="edit_page_1" method="post">
<input id="page_title" name="page[title]" type="text">
<input name="commit" type="submit" value="Update Page">
</form>
I run two kinds of feature specs, those that are the same no matter what the language, and those that are I18N specific (for internationalization testing).
The problem is there is no clear way to click that submit button with capybara, unless I'm missing the obvious. I would expect simply click('commit')
to do the trick.
- Using
click_button('Update Page')
works but is obviously language specific and can't be used with both the New and Edit templates even though they render the same form template. - Adding an id to the submit button works, but I strongly dislike changing the code exclusively because the test requires it.
- Using a css or xml matcher both looks ugly (a user would never know/care about accessing an element that way) and it is overkill.
Best Answer
In the end a macro was the answer I needed as apparently there is nothing native in capybara.
This gets included in spec_helper.rb
I used
:type => :feature
so it gets included only in the integration tests.In the integration tests you can use it like this:
Of course
submit_form
can also be used insidewithin
blocks and with:js => true
.