Receiving nil exception in rake tests

I’ve been doing some really simple rails testing, going along with
standard “red light… green light…” back-and-forth-ing.

All of a sudden, rake was reporting that there were “Test failures” but
not showing any stack trace. I went into
/usr/local/ruby/…/rails/lib/tasks/testing.rake
and looked at the source that ran the tests.

I found these lines:

desc ‘Test all units and functionals’
task :test do
Rake::Task[“test:units”].invoke rescue got_error = true; puts
'Unit test error: ’ + $!.inspect
Rake::Task[“test:functionals”].invoke rescue got_error = true; puts
'Functional test error: ’ + $!.inspect

if File.exist?(“test/integration”)
Rake::Task[“test:integration”].invoke rescue got_error = true; puts
'Integration test error: ’ + $!.inspect
end

raise “Test failures” if got_error
end

The extra statements in the rescue blocks are my own. That is, I added
; puts 'Unit test…

Running rake again, I now get
‘Unit test error: nil’
/usr/local/bin/ruby -Ilib:test
“/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb”
Functional test error: nil
/usr/local/bin/ruby -Ilib:test
“/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb”
Integration test error: nil
rake aborted!
Test failures

Can anybody help me diagnose why these tests are failing? I can tell
you that I’m definitely not even getting into any of the test case
bodies, since they have print statements that aren’t getting executed.

Thanks,
gcn

My own further digging, in case it helps others:

I changed the task description to read as follows:


desc ‘Test all units and functionals’
task :test do
begin
Rake::Task[“test:units”].invoke
rescue => err
got_error = true
puts “Error in Unit tests: #{err.message}”
puts err.backtrace
end

begin
Rake::Task[“test:functionals”].invoke
rescue => err
got_error = true
puts “Error in Functional tests: #{err.message}”
puts err.backtrace
end

if File.exist?(“test/integration”)
begin
Rake::Task[“test:integration”].invoke
rescue => err
got_error = true
puts “Error in Integration tests: #{err.message}”
puts err.backtrace
end
end

raise “Test failures” if got_error
end

there’s probably some DRY-ing to be done on the error printing, but I
HIGHLY recommend the rails project incorporate this code into the rake
test task. (Alas, I can’t submit it now because the rails Trac is
down.)

My error ended up being something about table duplication, and was
relatively easy to fix, but I had a very hard time diagnosing it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs