From: Hugh Sasse Staff Elec Eng Date: 2000-11-03T00:15:48+09:00 Subject: [ruby-talk:5996] Re: More RubyUnit questions. On 15 Aug 2000, Dave Thomas wrote: > Hugh Sasse Staff Elec Eng writes: > > > module RUNIT class TestCase > > def TestCase.suite > > TestSuite.new(self) > > end > > end > > end > > > > def TestCase.suite looks like the definition of a singleton method, but it > > is not because it is not defining a method of a particular instance. What > > is this? > > You are right, it _is_ a singleton method, but of class > RUNIT::TestCase. > > The rule here is straightforward, but gets confusing because of all > the weird terminology. > > "If a method is defined as > > def x.y > end > > then 'y' must be called with a received of 'x' (or a subclass of x)." OK... > > So: > > def TestCase.suite > end > > must be called as TestCase.suite(....), and > > d = Dave.new > def d.getSomeSleep > end > > must be called with a receiver of 'd'. Hmmm, so why is this being done *inside* the class definition of TestCase, because non-singleton methods defined there can only have receivers of TestCase anyway? What extras do you get? Doing this outside has its use like your getSomeSleep example; I can see that. > > > > So, back to the TestSuite thing. The 'suite' method is used to return > a list of the tests to be run. The default behavior is to construct a > list of all the methods in the receiver whose names begin with > 'test_'. However, you can override this if you want. > Oh. Ok I will explore this some more.... > > require 'runit/testcase' > require 'runit/cui/testrunner' > > class TestCoffee < RUNIT::TestCase > def setup > @pot = brew > end > def test_full > assert(@pot.full) > assert(@pot.temperature > 80) > end > def test_aroma > sniffer = Nose.new > assert_equal("rich, dark aroma", sniffer.sniff(@pot)) > end > # and so on > end > > # build a list of tests, and run them > RUNIT::CUI::TestRunner.run(TestCoffee.suite) Yes, that is nice to have. > > Regards > > > Dave > Thank you, Hugh hgs@dmu.ac.uk