How to include unit tests in a ruby module?

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

    Just found one way to prevent the unit test from being executed when the module is required from a script. There is a flag in unit.rb in .../lib/ruby/1.8/test/ to set to true.

    Combined with samg trick (thanks again), we can write:

    if (__FILE__ != $0)
        Test::Unit.run = true  ### do not run the unit tests
    end
    

提交回复
热议问题