Rails 4 的test_helper
中使用 Minitest::Spec
和 ActiveSupport::TestCase
有什么区别?
该项目旨在实现Rails TestCase中的MiniTest。 类。您的测试将继续继承自
ActiveSupport::TestCase
,现在将支持规范 DSL。 Github 上的 Minitest
这意味着您不必使用 Minitest::Spec
,只需一直使用 ActiveSupport::TestCase
即可在代码中获得一些约定。
编辑:当你不使用minitest-rails gem时,你必须register_spec_type
class ControllerSpec < MiniTest::Spec
end
# Functional tests = describe ***Controller
MiniTest::Spec.register_spec_type( /Controller$/, ControllerSpec )
除了 rspec 之外,我从未实际使用过任何东西,但根据他们的公共 API,ActiveSupport::TestCase 只支持在引发错误时进行测试,而 Minitest::Spec 对测试成功数据库查询以外的内容有更多的支持。