# Iterator behaviour

**URL:** <https://www.ruby-forum.com/t/iterator-behaviour/79916>\
**Category:** Ruby\
**Created:** [December 20, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/iterator-behaviour/79916 "2006-12-20T17:54:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [December 20, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/iterator-behaviour/79916/1 "2006-12-20T17:54:06Z")

</div>

I have a harness I’m using for testing with Watir. It has become  
apparent that the iterator is loading the tests defined based on the  
order they appear in the directory as opposed to the order in the  
testlist.

File.open(‘testlist.txt’).each\_line do |entry|  
self.send(:define\_method, entry.strip){ load “#{entry.strip}.rb”}

so if the testlist read something like

test\_aac  
test\_aab  
test\_aaa

instead of executing them in the order above it would do

test\_aaa  
test\_aab  
test\_aac

I’m probably being thick, but I’m not spotting where my iterator is  
going wrong?

---

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [December 22, 2006, 12:13pm UTC](https://www.ruby-forum.com/t/iterator-behaviour/79916/2 "2006-12-22T12:13:47Z")

</div>

I’m doing the ugly thing just now and using something like this

test\_001\_aaa  
test\_002\_aac  
test\_003\_aab

obviously this isn’t nice as it necessitates retaining a mapping of  
tests to order, which is what I wanted to avoid. I had wanted to be able  
to select lists of _any_ tests in any order, thus creating suites out of  
arbitrary test components.
