I recently noticed my test database is not being cleaned up after my tests run if my tests subclass Test::Unit::TestCase. If my tests subclass ActiveSupport::TestCase, everything is cleaned up properly.
我最近注意到,如果我的测试继承了Test :: Unit :: TestCase,我的测试数据库在运行测试后没有被清理。如果我的测试子类是ActiveSupport :: TestCase,那么所有内容都会被正确清理。
Can anyone explain why, and/or provide an explanation of using one versus the other?
任何人都可以解释为什么,和/或提供使用一个与另一个的解释?
I am using shoulda and factory_girl.
我正在使用shoulda和factory_girl。
Thanks.
谢谢。
1 个解决方案
#1
19
If you take a look at the code, you'll see ActiveSupport::TestCase
has a lot of of setup and utility functions for testing Rails. Older versions of Rails used to use Test::Unit::TestCase
with a lot of mixins, but moved to subclassing a while ago.
如果你看一下代码,你会发现ActiveSupport :: TestCase有很多用于测试Rails的设置和实用工具。较旧版本的Rails曾经使用过很多mixins的Test :: Unit :: TestCase,但是前一段时间转移到子类化。
If you're testing a Rails app, you should subclass ActiveSupport::TestCase
or ActionController:TestCase
for controllers. The generators will do this automatically, so you should not have to think about it most of the time.
如果您正在测试Rails应用程序,则应该为控制器创建ActiveSupport :: TestCase或ActionController:TestCase的子类。生成器会自动执行此操作,因此您不必在大多数时间考虑它。
#1
19
If you take a look at the code, you'll see ActiveSupport::TestCase
has a lot of of setup and utility functions for testing Rails. Older versions of Rails used to use Test::Unit::TestCase
with a lot of mixins, but moved to subclassing a while ago.
如果你看一下代码,你会发现ActiveSupport :: TestCase有很多用于测试Rails的设置和实用工具。较旧版本的Rails曾经使用过很多mixins的Test :: Unit :: TestCase,但是前一段时间转移到子类化。
If you're testing a Rails app, you should subclass ActiveSupport::TestCase
or ActionController:TestCase
for controllers. The generators will do this automatically, so you should not have to think about it most of the time.
如果您正在测试Rails应用程序,则应该为控制器创建ActiveSupport :: TestCase或ActionController:TestCase的子类。生成器会自动执行此操作,因此您不必在大多数时间考虑它。