On 10/22/05, Trans <transfire / gmail.com> wrote:
> Don't know how much gulf this can take, but I sure would like as small
> a version as I can get.
>
>   paths = File.expand_path(File.dirname(__FILE__)).split('/')
>   paths.size.downto(1) do |i|
>     f = (paths.slice(0..i)+['test']).join('/')
>     $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f)
>   end
>   raise unless $TESTDIR

I believe you mean golf? ;)

Here are a couple options (probably not the shortest though):

paths = File.expand_path(File.dirname(__FILE__)).split('/')
while paths.length > 1
  f = (paths+['test/FIXTURE']).join('/')
  $TESTDIR = f if File.directory?(f)
  paths.pop
end
raise unless $TESTDIR

path = File.expand_path(File.dirname(__FILE__))
until path == '/'
  f = File.join(path,'test/FIXTURE')
  $TESTDIR = f if File.directory?(f)
  path = File.dirname(path)
end
raise unless $TESTDIR

Ryan