Missing GEM causes misleading “use_transactional_fixtures” error
A lot of people out there on the net are getting frustrated by this error message coming out of their unit tests:
undefined method `use_transactional_fixtures=' for Test::Unit::TestCase:Class (NoMethodError)
I was recently getting this in my unit tests on my continuous integration server. The problem is that this has message nothing to do with the actual error. Rake has this bad habit of silently swallowing useful errors. Sometimes is just stops without saying anything, and other times it gives a completely incorrect message like this one.
In my case, the problem was a missing gem on the continuous integration server.
I’ve been working on patches to address these bad-error-message issues, but I haven’t yet gone through the effort of figuring out how to contribute them into the master source tree. I haven’t developed a patch to catch the root cause behind the ‘use_transactional_fixtures’ error above yet. But here’s one that catches database config errors and a bunch of others that would otherwise be silently swallowed:
Go into /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/testing.rake and change the task :test method to read:
desc 'Test all units and functionals'task :test do error_place="" Rake::Task["test:units"].invoke rescue error_place += "test:units: #{$!}" Rake::Task["test:functionals"].invoke rescue error_place += "test:functionals: #{$!}" if File.exist?("test/integration") Rake::Task["test:integration"].invoke rescue error_place += "test:integration: #{$!}" end
raise "Test failures in #{error_place}" if error_place != ""end
Compare to the official version. Note what happens to exceptions: nothing. This patch has been invaluable for configuration on my CI server. To repeat, this patch does not address the "use_transactional_fixtures" error. When I figure out a patch for that one I’ll post it.
Peter Marklund has written a patch for this same problem which is IMHO more elegant. See http://marklunds.com/articles/one/317 .
Thanks, Peter.