How to make minitest available in ruby module

127 views Asked by At

I am trying to make a module that has a bunch of helper definitions. Some of the defs use assert from Minitest::Assertions. How can i get access to these assertions inside a module. Mock example below

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

There are 1 answers

0
Panic On BEST ANSWER

You need to define an instance accessor named 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

We can use TestHelpers this way:

class FooTest
  include TestHelpers
end

test = FooTest.new
test.assert_true #=> true