views:

45

answers:

1

My gem semantictext has a bunch of test data that it reads for regression testing.

Here's the project: http://github.com/dafydd/semantictext

Here's an example test that I want to be able to run directly from the gem: http://github.com/dafydd/semantictext/blob/master/test/test%5Fdocument.rb (look for text "SANDBOX")

I normally develop it in a directory called "semantictext" and have the environment variable SANDBOX set to the path of the directory above "semantictext" - so that I can reference any file in the project using ENV['SANDBOX'].

When the gem is installed as a package, is there a way that the test/unit test running from rake can:

1) know that it's running from a gem? and

2) know the path to it's semantictext directory within the local rubygems repository?

I want to make it effortless to be able to run all the tests from any gem installation. This would make my continuous integration a bit easier and allow me to write better gems.

Thanks, Dafydd

+1  A: 

You can find out the directory of the current file using:

File.dirname(__FILE__)

This will allow you to build up a relative path to whatever file you need to access.

Pelle