From: Massimiliano Mirra - bard Date: 2004-08-28T07:45:33+09:00 Subject: Re: Literate testing? Mauricio Fern叩ndez writes: > I believe you can make it look a bit better by using Kernel#caller > and Module#method_added; I confess I have absolutely no idea how. :-) > it would also be nice to generate test > cases for Test::Unit (for instance by defining the test_* methods in > MyClass::LiterateTests so that they can be included in a test suite > later). Nice. I tried, and the last call shows test_* methods get defined, but Test::Unit says `No tests were specified.'. require "test/unit" module Literate def method_missing(id, *args, &block) if id.to_s =~ /example_/ name = Regexp.last_match.post_match self::LiterateTests.send(:define_method, "test_#{name}".intern, &block) else super(id, *args, &block) end end end class Calculator extend Literate module LiterateTests end example_add do assert @calc.add(2, 8) == 10 end def add(a, b) return a + b end example_div do assert @calc.div(10, 2) == 5 end def div(a, b) return a / b + 1 end end class TestCalculator < Test::Unit::TestCase include Calculator::LiterateTests def setup @calc = Calculator.new end end p TestCalculator.public_instance_methods