Forum: RSpec how to check for empty field value?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
387fb00ef9d6d523d43018d9c81ab36b?d=identicon&s=25 Jonathan Linowes (Guest)
on 2008-12-30 05:02
(Received via mailing list)
# Then /^the email_confirmation field should be cleared$/ do
#   #how to write this ????
#   #selector( "input[name=user[email_confirmation]")[:value].should
be_blank
# end
57e939ff00f9df2670a09f417c08da5e?d=identicon&s=25 Josh Knowles (Guest)
on 2008-12-30 06:58
(Received via mailing list)
On Mon, Dec 29, 2008 at 10:59 PM, Jonathan Linowes
<jonathan@parkerhill.com> wrote:
> # Then /^the email_confirmation field should be cleared$/ do
> #   #how to write this ????
> #   #selector( "input[name=user[email_confirmation]")[:value].should
> be_blank
> # end

Are you using Webrat?  If so try:

field_labeled("Email Confirmation").value.should be_nil

--
Josh Knowles
phone: 509-979-1593
email:  joshknowles@gmail.com
web:    http://joshknowles.com
387fb00ef9d6d523d43018d9c81ab36b?d=identicon&s=25 Jonathan Linowes (Guest)
on 2008-12-30 15:39
(Received via mailing list)
I'll try that, but by the method name, I assume it looks for a
<label> tag for the field rather than the name attribute of the
<input> ?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-12-30 16:13
(Received via mailing list)
On Tue, Dec 30, 2008 at 8:34 AM, Jonathan Linowes
<jonathan@parkerhill.com> wrote:
>>
>> Are you using Webrat?  If so try:
>>
>> field_labeled("Email Confirmation").value.should be_nil
>>

> I'll try that, but by the method name, I assume it looks for a <label> tag
> for the field rather than the name attribute of the <input> ?
>

That is correct, and encourages a good habit of associating labels
with input fields in the HTML. That way, steps can say things like
"the Email Confirmation field should be empty" instead of "the
email_confirmation field should be empty."

If you don't want to be encouraged to do that, you can use this instead:

  field_with_id('user_email_confirmation').value.should be_blank

or some such.

HTH,
David
This topic is locked and can not be replied to.