如何在ruby模块中使用minitest

时间:2018-06-17 05:22:03

标签: ruby capybara minitest assertions

我正在尝试创建一个包含一堆帮助程序定义的模块。一些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

1 个答案:

答案 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