[Wtr-general] Organizing tests

Bret Pettichord bret at pettichord.com
Wed Apr 26 11:26:34 EDT 2006


Actually, the best way to do this is to put test root in your load path.

  $LOAD_PATH << File.dirname(__FILE__) + '/../'
  require 'lib/variables'

The problem with Keith's solution is that you'll end up requiring the same
file from different tests via different paths. The semantics of require is
that it won't load a library if it has already been loaded, but if you are
loading the same file but using a different path in your require statement,
require will think it is a different library and load it again. If it has
constants you will get warnings about redefining constants.

Bret

On 4/24/06, Keith Lancaster <klancaster1957 at gmail.com> wrote:
>
> You might consider something like this - putting all your shared files in
> a
> common lib directory.
>
> /test_root
> --/lib
>     -- variables.rb
>     -- includeme.rb
>
> --/login_tests
>     -- testfile.rb
>     -- testfile2.rb
> --/other_functional_area
> etc.
>
> Then in your test files, you could put
>
> require File.dirname(__FILE__) + '/../lib/variables'
>
> This should load the variable.rb file (notice that .rb is not needed)
> regardless of where you are running it from. If you don't want to use the
> lib directory idea, you can use the same method - just change the require
> line to
>
> require File.dirname(__FILE__) + '/../variables'
>
> HTH,
> Keith
>
>
>
> On 4/24/06 4:34 PM, "Michael Moore" <stuporglue at gmail.com> wrote:
>
> >> When I try to run login.rb from a sub folder, it fails on "require
> >> 'variables.rb'", as it's looking in the current directory, which is a
> >> folder down from variables.rb.
> >>
> >> Is there a way to let login.rb know where variables.rb is at, without
> >> putting in a hard path?
> >
> > I found something online that mentioned sending DOS commands, so now
> > my loads in the subfolders look like this (and work)
> >
> > Dir.chdir("..")
> > load 'login.rb'
> > Dir.chdir("Tests")
> >
> > It moves me up to run the login script, then back down to run the rest
> > of the test.
> >
> > Thanks,
> > --
> > Michael Moore
> > -------------------------------
> > www.stuporglue.org -- Donate your used computer to a student that needs
> it.
> > www.ubuntu-utah.org -- In Utah? Interested in Ubuntu? Come join us.
> >
> > _______________________________________________
> > Wtr-general mailing list
> > Wtr-general at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/wtr-general
>
>
> _______________________________________________
> Wtr-general mailing list
> Wtr-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060426/0b1e91da/attachment.html 


More information about the Wtr-general mailing list