【问题标题】:Difference between Minitest::Spec and ActiveSupport::TestCaseMinitest::Spec 和 ActiveSupport::TestCase 的区别
【发布时间】:2014-02-14 15:16:33
【问题描述】:

在 Rails 4 的 test_helper 中使用 Minitest::SpecActiveSupport::TestCase 有什么区别?

【问题讨论】:

    标签: ruby-on-rails testing minitest


    【解决方案1】:

    该项目旨在在 Rails TestCase 中启用 MiniTest 类。您的测试将继续继承自 ActiveSupport::TestCase,现在将支持规范 DSL。 Minitest on Github

    这意味着您不必使用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 )
    

    【讨论】:

      【解决方案2】:

      我实际上从未使用过除 rspec 之外的任何东西,但根据他们的公共 API,ActiveSupport::TestCase 仅支持在引发错误时进行测试,而Minitest::Spec 更多地支持测试除了成功的数据库查询之外的东西。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-02
        • 2015-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多