我正在尝试创建一个包含一堆帮助程序定义的模块。一些defs使用来自Minitest :: Assertions的断言。如何在模块内访问这些断言。下面的模拟示例
module Helper
require 'minitest'
TEST = Minitest::Assertions
module Helper::Scripts
def self.assertion
TEST.assert true
end
end
end
Helper::Scripts.assertion #undefined assert
答案 0 :(得分:0)
您需要定义名为assertions
module TestHelpers
include Minitest::Assertions
# Number of assertions executed in this run
attr_accessor :assertions
def assert_true
self.assertions = 0
assert true
end
end
我们可以这样使用TestHelpers:
class FooTest
include TestHelpers
end
test = FooTest.new
test.assert_true #=> true