Searching for empty form fields using rspec

July 21, 2009

Took me far to long to work out how to do this!

To find an empty input field we can look for

"input[type=text][value='']"

e.g.

response.body.should have_tag("input[type=text][value='']")

This is useful when filling in forms badly to make sure your bad values still remain when you return to the form to edit them.