How to include unit tests in a ruby module?

后端 未结 4 1357
攒了一身酷
攒了一身酷 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:48

    Personally I've never heard of anyone trying to do this in Ruby. It's definitely not a standard practice. That said you may be able to leverage this trick:

    if __FILE__ == $0
      # Do something.. run tests, call a method, etc. We're direct.
    end
    

    The code in the if block will only execute if the file is executed directly, not if it's required by another library or application.

    More ruby tricks here: http://www.rubyinside.com/21-ruby-tricks-902.html

提交回复
热议问题