Mass Find/replace for Rails Tests

May 26th, 2009

After upgrading an old project to Rails 2.3.2,my tests were failing to run, bombing out with an error like:

./test/unit/my_model.rb:4: undefined method `fixtures' for MyModelTest:Class (NoMethodError)

This was because in Rails 2.3.2, tests have to derive from ActiveSupport::TestCase, and not the old Test::Unit::TestCase.

A quick find and replace soon has us up and running again:
perl -pi -w -e 's/Test::Unit::TestCase/ActiveSupport::TestCase/g;' test/unit/*.rb

Effectively, this one-liner searches through all the files in the test/unit directory, and replaces all instances of “Test::Unit::TestCase” with “ActiveSupport::TestCase”

Categories: Rails

Tags: , Leave a comment

Like This Post?

Subscribe for more...
Feed

http://www.mendable.com / Mass Find/replace for Rails Tests