Rails: How do I write tests for a ruby module?

前端 未结 6 987
春和景丽
春和景丽 2021-01-31 02:22

I would like to know how to write unit tests for a module that is mixed into a couple of classes but don\'t quite know how to go about it:

  1. Do I test the instanc

6条回答
  •  渐次进展
    2021-01-31 02:38

    In minitest since each test is explicitly a class you can just include the module to the test and test the methods:

    class MyModuleTest < Minitest::Test
       include MyModule
    
       def my_module_method_test
         # Assert my method works
       end
    end
    

提交回复
热议问题