Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it still possible to use test-unit in rails 4?

After upgrading from Rails 3.2 to Rails 4, my app works, but my tests, written with test-unit, are a disaster.

Minitest is rumored to be "compatible" with test-unit. However, if I attempt to use the (now bundled) Minitest, there are a raft of differences - from the assert* statement names and parameters to (clearly) many other things things both large and subtle.

If I instead try to avoid Minitest and attempt to keep my test-unit gem in my Gemfile, rake test explodes, saying,

undefined method 'refute_predicate' for class 'ActiveSupport::TestCase'

This results from having called

require 'rails/test_help'

:(

I have been searching for a while but have not yet figured out any way to continue using test-unit. The only alternative would seem to be a (for us, massive) refactoring of our test code, since something like 80% of our tests are broken in some way or other by Minitest's incompatibilities with test-unit.

Yet reading i.e. http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/ and http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0 I find no mention of this in substance - I feel like must be missing something.

Is it possible to make Minitest more compatible with test-unit in a systematic way? Or to continue using test-unit in Rails 4?

like image 781
David W Avatar asked Jul 24 '13 19:07

David W


1 Answers

Are you subclassing: Test::Unit::TestCase and not ActiveSupport::TestCase?

Maybe try adding minitest_tu_shim to your test group:

https://github.com/seattlerb/minitest_tu_shim

or make sure to subclass ActiveSupport::TestCase

like image 133
rainkinz Avatar answered Oct 26 '22 22:10

rainkinz