[Ruby] Dynamic tests

Geoffrey Grosenbach boss at topfunky.com
Thu Oct 12 18:20:28 PDT 2006


I'm using define_method to automate the building of some repetitive  
test cases.

This works great when running the test file directly, but doesn't  
work when using the Rake Test task (the dynamically created methods  
are never created):

Is there a clean way to do this with the Rake::TestTask? Or, do I  
just need to change the test task so it executes the relevant file  
from the shell?

Geoff



# Test file
%w(test_this test_that).each do |name|
   define_method(name) do
     # Some test code...
   end
end

# Rake task
desc "Run the mailer tests in test/mailer"
Rake::TestTask.new "mailer" => [ 'db:test:prepare' ] do |t|
   t.libs << 'test'
   t.pattern = "test/mailer/**/*_test.rb"
   t.verbose = true
end




More information about the Ruby mailing list