Hugh Sasse Staff Elec Eng <hgs / dmu.ac.uk> writes:

> module RUNIT
>     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)."

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'.



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.


     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)



Regards


Dave