Read more

Check that a text field is empty with Cucumber

Henning Koch
September 15, 2010Software engineer at makandra GmbH

This will not work (it always passes):

Then the "Title" field should contain ""
Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

The value is turned into a regular expression, and an empty regular expression matches any string!

Do this instead for Capybara:

Then the "Title" field should contain "^$"

And do this step for Webrat:

Then /^the "([^"]*)" field should( not)? be empty$/ do |field, negate|
  expectation = negate ? :should_not : :should
  field_labeled(field).value.send(expectation, be_blank)
end
Posted by Henning Koch to makandra dev (2010-09-15 19:21)