I'm finally getting around to taking a closer look at the Watir UnitTests and thought that I would start with the 'all_tests.rb' and 'core_tests.rb' scripts.  I'm having some trouble trying to understand *why* the paths are manipulated the way they are.

Both files are basically the same, just the [variable] list of test files called is different.  Here's the 'all_tests.rb' script:
---
TOPDIR = File.join(File.dirname(__FILE__), '..')
$LOAD_PATH.unshift TOPDIR

require 'unittests/setup.rb'

Dir.chdir TOPDIR
$all_tests.each {|x| require x}
---

Here's my understanding of what this script is doing:

1) Line one sets the variable = './..'   ( using a much more verbose way of doing it  ;) )
- Incidentally, I was unable to find any reference to the use of '__FILE__' anywhere.  Is that some special kind of dummy variable?  Can someone please tell me how/why this works?

2) Line two prepends './..' to the Ruby load path
- I don't understand the design choice behind this.  i.e. I don't know why the first two lines can't just be squished into this one line - as in:
   $LOAD_PATH.unshift './..'
( I must be missing something important further down the scripts that I haven't gotten to yet. )

3) skip line three for the moment..

4) Line four changes the current directory to the parent of the current (i.e. essentially 'cd ..')

5) Back to Line three - now that we are one directory back/up, let's _require_ the file that *used to be* in the current directory, but now is in the subdirectory called 'unittests'

6) Finally, call/require all the test files (where each element in the variable array contains the path 'unittests/' before the filename)

Did I get that right?

So my question is this:
- Why do the UnitTest scripts go to all the trouble of prepending the parent path to the Ruby Load Path, then change to the parent path, only to then call all the files in the desired subdirectory?

Is there something that I'm missing regarding the value of directory *position* when running Ruby/Watir scripts?  I am not doing this directory one-two step in my scripts and am wondering if it is something that I should add or not.

Please let me know what I am missing here.  Thanks.

Paul.


_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to