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

可紊 提交于 2019-12-08 15:48: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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/17843523/is-it-still-possible-to-use-test-unit-in-rails-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!