如何在类外使用Minitest断言?

时间:2018-06-22 08:16:47

标签: ruby minitest

我正在尝试:

require 'minitest'
Minitest::Assertions::assert_equal(1, 1)

不起作用:

NoMethodError: undefined method `assert_equal' for Minitest::Assertions:Module

正确的方法是什么?方法does exist

1 个答案:

答案 0 :(得分:1)

module Assertions
  extend Minitest::Assertions

  class << self
    attr_accessor :assertions
  end

  self.assertions = 0
end

Assertions.assert(true)
Assertions.assert(false)

Minitest :: Assertions模块希望能够增加名为assertions的实例访问器。

http://docs.seattlerb.org/minitest/Minitest/Assertions.html