[Rubygems-developers] The path to Environmentally Clean Test
chad at chadfowler.com
Tue Apr 13 08:14:52 EDT 2004
On 12/4/2004, at 9:38 PM, Jim Weirich wrote:
> 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
> 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 variables.
This all looks great to me. I just made a change on the wiki docs to
reflect Gem.path vs. $GEM_PATH.
> 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
I'll add this to my list, though it may be tomorrow night before I can
get to it. Feel free to fix it before then if you're motivated. :)
> 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
> not sure.
This was changed on Jan. 9. I'm working from ruby 1.9, so it's my
fault that we have assert_raise. What do you think we should do? It
would be nice to test on both 1.8.1 and 1.9.*.
More information about the Rubygems-developers