How to include unit tests in a ruby module?

后端 未结 4 1368
攒了一身酷
攒了一身酷 2021-01-05 13:53

I\'m trying to include the unit tests for a module in the same source file as the module itself, following the Perl modulino model.

#! /usr/bin/env ruby

req         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-05 14:47

    It's actually not that uncommon in Ruby though it's certainly not the common practice in Rails.

    One of the issues you may be running into is the same as this post which is that modules really should be included in classes in order to test them. It's certainly possible to test a module by including it in your test case but you're testing whether the module works when mixed into Test::Unit::TestCase, not that it'll work when you mix it into something more useful.

    So unit tests should probably live on the class file or if you just want generally available methods use a class function instead of a module.

提交回复
热议问题