Morton Goldberg
11/2/2007 4:21:00 AM
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