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

2

10

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?

Cuirass answered 24/7, 2013 at 19:46 Comment(3)
Can you be more specific on what incompatibilities you've run into?Conover
assert_include vs. assert_includes, assert_not_include vs. assert_not_includes, assert_false vs. refute, assert_true vs. assert. The process_with_new_base_test method is missing (it was necessary to wrap this to prevent smearing of controller instance variables between requests on controller tests). With a bunch of tests still broken, I gave up at this point.Cuirass
Would you be up to remote pairing on this? Shoot me an email and we'll set it up.Conover
U
3

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

Unstick answered 24/7, 2013 at 20:20 Comment(0)
B
0

Yes Rails support Test::Unit. Here is the guide for it.

http://guides.rubyonrails.org/testing.html

Use a global search & replace on your test cases to change the method names.

Here is an integration test:

class UserFlowsTest < ActionDispatch::IntegrationTest

Here is a controller test:

class UsersControllerTest < ActionController::TestCase

Try rails new app to copy the automatically generated helpers and framework files and see examples.

Bucksaw answered 1/6, 2014 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.