[LRUG] testing a simple ruby project (no rails - just ruby)

Dafydd Rees daf at dafydd.net
Tue Feb 19 09:33:06 PST 2008


Hello,

I'm trying to put together a really simple ruby project and I could do 
with a little help please.

I just want to
- put my code in one subdirectory (say 'lib'),
- my tests in another (say 'test')
- and have a  Rakefile with a default target
   ...that runs all the tests that test/unit can find
      in all the *.rb files under 'test'.

I can't believe it's as difficult as it seems(!)

So far, I have this Rakefile:

----------- 8< ------------------------------------------------
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

Rake::TestTask.new(:default) do |t|
   t.libs << 'test'
   t.test_files = './test/*.rb'
   t.verbose = true
end
-------------8<-------------------------------------------------

QUESTION 1: It lies about the number of tests run (why?)

This sort of works - it runs both tests that I have defined in rb files 
under 'test':

blackbook:~/workspace/x blah$ rake
(in /Users/blah/macbook/workspace/x)
/usr/local/bin/ruby -Ilib:test 
"/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb" 
"test/tc_a.rb" "test/tc_b.rb"
Loaded suite 
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader
Started
F
Finished in 0.007152 seconds.

   1) Failure:
test_fail(TC_MyTest) [./test/tc_b.rb:5]:
<false> is not true.

1 tests, 1 assertions, 1 failures, 0 errors

So why do I get "1 tests" - I have "tc_a.rb" and "tc_b.rb" as you can 
see from the rake output. (I know it's running both - because it can 
pick up failures in both test cases.)


QUESTION 2: How can I recursively pick up and run all the tests under 
the 'test' directory - just like it works in rails?


Cheers,
Dafydd
-- 
Dafydd Rees
www.dafydd.net
mobile 07968 486880



More information about the Chat mailing list