# Assertion loop in test/unit?

**URL:** <https://www.ruby-forum.com/t/assertion-loop-in-test-unit/119004>\
**Category:** Ruby\
**Created:** [November 2, 2007, 2:17am UTC](https://www.ruby-forum.com/t/assertion-loop-in-test-unit/119004 "2007-11-02T02:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [November 2, 2007, 2:17am UTC](https://www.ruby-forum.com/t/assertion-loop-in-test-unit/119004/1 "2007-11-02T02:17:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [November 2, 2007, 5:21am UTC](https://www.ruby-forum.com/t/assertion-loop-in-test-unit/119004/2 "2007-11-02T05:21:52Z")

</div>

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

> {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:

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

Regards, Morton
