[Rubygems-developers] Failing to test gem on install

Chad Fowler chad at chadfowler.com
Mon Jul 19 09:22:28 EDT 2004



On Sun, 18 Jul 2004, Gavin Sinclair wrote:

# Chad wrote:
#
# > # I've never seen a "ts_*.rb" file, and am digging through various
# > # projects' code now to try and get an idea for unit testing practice.
# > # Do you know of any good examples?
# >
# > I'd look to Nathaniel for good examples.  You're on Dave's pickaxe2
# > review list, right?  Have you looked at his unit testing chapter?
#
# Good idea; I will tonight.
#
# > # The fact remains that it's quite reasonable to manage unit tests
# > # _without_ such suite files.  I prefer to do so.[1]  So why should
# > # RubyGems target just one idiom?
# >
# > It's not really targeting just one idiom.  It currently requires that
# > you identify one file that, when loaded, will cause all of your test
# > cases to load.  You can do that however you want.  We could probably
# > even support some kind of Rakefile.  You could get them out of a
# > database, generate them randomly, require them from tc_*rb files,
# > whatever.  I don't think it can get much more flexible.  We _could_ add
# > a #test_files attribute to the gem specification, but we're probably
# > already going to have to add something like #test_require_path, and I
# > don't think it's worth cluttering the gem spec up even further for this.
#
# But I reckon a 'test_files' attribute would be enough in isolation.  (Or
# perhaps a 'test_files_pattern', like 'test/test*.rb', would be better.)
# Why is a 'test_require_path' needed?  If you have an array of test files,
# relative to the root of the gem, you can *load* them (not 'require') one
# by one, and then do the ObjectSpace thing.  You just have to make sure
# that the correct libraries (the ones being tested) are at the front of the
# LOAD_PATH.
#
# The unit tests are responsible for loading any supporting files (i.e. they
# need to know where they are using __FILE__).  The unit tests should not be
# responsible for manipulating LOAD_PATH, though.  That's better handled by
# an outside agent, be it RubyGems, Rake, or test/TEST.rb.
#
# I'm definitely interested in minimising gemspec clutter, which is why I
# think 'test_files_pattern' is the best solution.  It's easy to specify,
# and has no dependencies on anything else, within or without the gemspec.
#

After giving this some thought, I think the best way to do this is to
remain consistent with some of the other attributes that allow either one
or many values that point to files (like "extensions", "require_paths",
etc.).  We could rename the current #test_suite_file to #test_file and
then have a plural version #test_files.  Ultimately, they could all be
typical ts_* style test suite files, or any other custom thing that loads
TestCases.

Any other test-oriented people have an opinion?

Chad


More information about the Rubygems-developers mailing list