【问题标题】:Adding custom shoulda matchers to TestCase将自定义的 shoulda 匹配器添加到 TestCase
【发布时间】:2010-10-12 13:15:06
【问题描述】:

使用 shoulda 后,很明显 shoulda 不再使用宏(对于首选匹配器,它们都已弃用)例如:

should_allow_custom_test

已弃用以下内容:

should allow_custom_test

但是,我能找到的所有文档都是针对以前的宏设置的,方法是将它们放在 shoulda_macros 目录中。我认为同样可以使用自定义 ma​​tcher 来完成,但应该找不到它们。

我正在使用的匹配器位于http://gist.github.com/613522

如何在我的TestCase 中加入自定义匹配器

【问题讨论】:

    标签: ruby-on-rails testing shoulda


    【解决方案1】:

    深入研究 active_record.rb,看起来匹配器直接需要到 Test::Unit::TestCase 我认为您的要点将其纳入 ActiveSupport::TestCase - 不确定这是否有帮助......但可能值得一试。

    来自 active_record.rb:

    module Test # :nodoc: all
      module Unit
        class TestCase
          include Shoulda::ActiveRecord::Helpers
          include Shoulda::ActiveRecord::Matchers
          include Shoulda::ActiveRecord::Assertions
          extend Shoulda::ActiveRecord::Macros
        end
      end
    end
    

    【讨论】:

    • 谢谢,实际上可能是这样。我不久前放弃了并选择了自定义宏,因为这是谷歌这些天能找到的唯一例子。我将不得不再次尝试匹配器。
    猜你喜欢
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 2017-07-16
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    相关资源
    最近更新 更多