[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

assertion loop in test/unit?

Todd A. Jacobs

11/2/2007 1:17:00 AM

In the following snippet, the first two fields exist, the remaining do
not. However, the test correctly tells me that replyaddr is missing, but
never processes the last two items in the list:

def test_fields_exist
@fields = ['jobid', 'company', 'replyaddr', 'SEEKER_CC', 'RESUME_FILE']
@fields.each do |field|
assert(@reply_form.has_field?(field), "Field missing: #{field}")
end
end

Why is that?

--
"Oh, look: rocks!"
-- Doctor Who, "Destiny of the Daleks"

1 Answer

Morton Goldberg

11/2/2007 4:21:00 AM

0

On Nov 1, 2007, at 9:17 PM, Todd A. Jacobs wrote:

> In the following snippet, the first two fields exist, the remaining do
> not. However, the test correctly tells me that replyaddr is
> missing, but
> never processes the last two items in the list:
>
> def test_fields_exist
> @fields = ['jobid', 'company', 'replyaddr', 'SEEKER_CC',
> 'RESUME_FILE']
> @fields.each do |field|
> assert(@reply_form.has_field?(field), "Field missing: #
> {field}")
> end
> end
>
> Why is that?

AFAIK the Test::Unit framework always terminates a test method at the
first failure. To get what I think you are looking for, you might
write something like:

<code--not tested>
def test_fields_present
['jobid', 'company'].each do |field|
assert(@reply_form.has_field?(field), "Field missing: #{field}")
end
end
def test_fields_missing
['replyaddr', 'SEEKER_CC', 'RESUME_FILE'].each do |field|
assert(not @reply_form.has_field?(field), "Field present: #
{field}")
end
end
</code>

Regards, Morton