[Rubygems-developers] The path to Environmentally Clean Test
jim at weirichhouse.org
Mon Apr 12 22:38:22 EDT 2004
I feel like the EPA, espousing environmental protection and all that :-)
I'm working on getting the tests to run cleanly without referencing the
normal desktop environment. This is important because (a) we want the
tests to test what is in the working directory, not the installed
version of RubyGems, and (b) when you have dependencies on the
environment, the tests will run differently on different machines.
So, here's a quick summary of the changes I just committed.
(1) The rake file used to use a library function to run the tests.
Since Rake can be a gem, it may need to run require_gem to get to its
library. Unfortunately require_gem is what we are testing, so we can't
depend upon it working. So I moved the rake library function to a
scripts directory and updated the Rakefile to run the tests "inline".
Thus, better separation between test and environment.
(NOTE: Normally Rake runs in its own Ruby "VM" and there is no problem.
In the unit tests, the library code (using the installed gem) needed
to be loaded in the same VM as the test code (using the non-installed
VM). Did that make sense?)
(2) The next big environment dependency are the gem directories where
stuff is installed. This is controlled by Gem.dir and $GEM_PATH and are
calculated at load time (well, $GEM_PATH at least). I changed $GEM_PATH
to Gem.path everywhere in the code, and made both calculated upon
demand. I also added a GEM_HOME environment variable.
Gem.dir is the directory where installs will take place. There is a
default value (in the ruby dist directory), but if you give a value for
GEM_PATH, it will be used instead. This allows our tests to target
installs into temp directories without messing up installed stuff.
Gem.path is a list of gem directories to search for gems. It should
include Gem.dir (usually as the last entry). If you set the RUBY_GEMS
environment variable with a path-style list, this list will be used for
Gem.path. The Gem.dir directory will be appended to the list if it is
not already there.
Tests have been added for Gem.dir/Gem.path. If this behavior doesn't
make sense, we can easily change it.
Oh, Gem.clear_paths and Gem.use_paths are provided for making testing
easier. Gem.clear_paths clears the Gem.dir and Gem.path values so that
the next time they are needed they will be recalculated from scratch.
Gem.use_path(home, path_list) allows us to set the Gem.dir and Gem.path
values directly in a unit test without mucking around with environment
This is just the start to enable Environment clean testing. We need to
start using them now. At least *two* tests are still environmentally
sensitive because they were failing until I installed the latest CVS,
then they started passing (they were remote installer related).
Finally, just one more thing.
For some reason 'assert_raise' doesn't work on my system, but
'assert_raises' does. Is the is Test::Unit compatibility thing? I'm
-- Jim Weirich jim at weirichhouse.org http://onestepback.org
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
More information about the Rubygems-developers