Testing Wrap do testing 'that wrap can be included in a class' do assert do Class.new do include Wrap end end end testing 'that a method can be wrapped before it is defined' do assert do wrapped_class do assert_raises(NoMethodError){ new.foo() } wrap :foo assert_nothing_raised{ new.foo() } end end end testing 'that a method can be wrapped after it is defined' do assert do wrapped_class do def foo() 42 end assert{ new.foo() == 42 } wrap :foo assert{ new.foo() == 42 } end end end private def wrapped_class(&block) tc = self c = Class.new do include Wrap const_set(:TC, tc) def self.method_missing(method, *args, &block) case method.to_s when /^\Aassert/ const_get(:TC).send(method, *args, &block) else super end end module_eval(&block) end c end end BEGIN { testdir = File.dirname(File.expand_path(__FILE__)) rootdir = File.dirname(testdir) libdir = File.join(rootdir, 'lib') require File.join(libdir, 'wrap') require File.join(testdir, 'testing') }