assertion loop in test/unit?

  • Thread starter tjacobs-sndr-019fdb
  • Start date
T

tjacobs-sndr-019fdb

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?
 
M

m_goldberg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top