Sha256: 903555066f9d65a62274fbf70d6e890ec4362de3c9f03d57616f39a5ae477cbb
Contents?: true
Size: 1.97 KB
Versions: 1
Compression:
Stored size: 1.97 KB
Contents
require 'nano/kernel/sym_esc' require 'yaml' $test_mode = false $test_failures = [] module UnitTestKernel def assert_on! $test_mode = true end def assert_off! $test_mode = false end def assert!(&blk) old = $test_mode $test_mode = true r = blk.call $test_mode = old return r end def no_assertion!(&blk) old = $test_mode $test_mode = false r = blk.call $test_mode = old return r end end class Object include UnitTestKernel end module UnitTesting class Failure def to_yaml_properties [ '@self', '@method', '@args', '@caller' ] end def initialize( slf, meth, args, callr ) @self = slf @method = meth @args = args @caller = callr end end TRANSPARENT_ASSERTIONS = %w{ == === eql? equal? kind_of? include? member? empty? nil? has_key? key? respond_to? between? } def self.advise_assertions ObjectSpace.each_object(Module) do |m| TRANSPARENT_ASSERTIONS.each do |meth| nmeth = "assert_#{sym_esc(meth)}" if m.method_defined?(meth) m.class_eval <<-HERE alias :#{nmeth} :#{meth} def #{meth}(*args) if $test_mode r = nil no_assertion! { r = #{nmeth}(*args) unless r $test_failures << Failure.new( self, :"#{meth}", args, caller[2..-1] ) end } return r else return #{nmeth}(*args) end end HERE end #if end #do end #do end #def def self.report y $test_failures end end class Object include UnitTestKernel end UnitTesting.advise_assertions =begin testing class X def a 1 end end class TestX < X def test_a assert! { a == 1 a == 2 } end end x = TestX.new x.test_a UnitTesting.report =end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
reap-4.0.0 | lib/reap/test.rb |