Include module in all MiniTest tests like in RSpec

前端 未结 3 2046
滥情空心
滥情空心 2021-02-14 14:08

In RSpec I could create helper modules in /spec/support/...

module MyHelpers
  def help1
    puts \"hi\"
  end
end

and include it

3条回答
  •  情深已故
    2021-02-14 14:54

    One thing I will do is create my own Test class inheriting from Minitest::Test. This allows me to do any sort of configuration on my base test class and keeping it isolated to my own project1.

    # test_helper.rb
    include 'helpers/my_useful_module'
    module MyGem
      class Test < Minitest::Test
        include MyUsefulModule
      end
    end
    
    # my_test.rb
    include 'test_helper'
    module MyGem
      MyTest < Test
      end
    end
    

    1 This is most likely unneeded, but I like keeping all my gem code isolated.

提交回复
热议问题