3

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

should_allow_custom_test

推荐使用以下内容:

should allow_custom_test

但是,我能找到的所有文档都是通过将它们放在shoulda_macros目录中来进行前宏设置的。我认为可以使用自定义匹配器来完成相同的任务,但应该找不到它们。

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

如何在我的 's中包含自定义匹配器?TestCase

4

1 回答 1

2

深入研究 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
于 2010-11-02T14:32:19.183 回答