On 2002.10.04, Phlip <phlip_cpp / yahoo.com> wrote:
> class VehicleTest
>         def test_wheels
>                 testee = warmUp()
>                 assert_equal ( myWheelCount(), testee.wheels() )
>         end
> end
> 
> class CarTest < VehicleTest
>         def warmUp()
>                 @testee = Car.new()
>                 return @testee
>         end
> 
>         def myWheelCount
>                 return 4
>         end
> end
> 
> 
> class TruckTest < VehicleTest
>         def warmUp()
>                 @testee = Truck.new()
>                 return @testee
>         end
> 
>         def myWheelCount
>                 return 8
>         end
> end

Another way, but with less code:

  def assert_wheels_equal expected, klass
    assert_equal expected, klass.new.wheels
  end

  class CarTest
    def test_wheels
      assert_wheels_equal 4, Car
    end
  end

  class TruckTest
    def test_wheels
      assert_wheels_equal 8, Truck
    end
  end

Maybe I'm just being thrown by the simplicity of the example.
Are there more complex cases that justify the extra base class?

I suppose that this version doesn't "force" subclasses to make
the assertion.

Another way to phase the Phlip version is just:

  class VehicleTest
    def test_wheels
      assert_equal myWheelCount, classUnderTest.new.wheels
    end
  end

  class CarTest < VehicleTest
    def classUnderTest
      Car
    end
    def myWheelCount
      4
    end
  end

  class TruckTest < VehicleTest
    def classUnderTest
      Truck
    end
    def myWheelCount
      8
    end
  end

 - Ryan King