views:

46

answers:

1

I have a test class:

require File.dirname(__FILE__) + '/../car.rb'
class CarTest < Test::Unit::TestCase

   def test_set_color
      assert_raise InvalidColorEntry "Exception not raised for invalid color" do
        Car.set_color("not a color")
      end
   end

end

InvalidColorEntry is an exception class that I placed in the car.rb file like so:

class InvalidColorEntry < Exception; end
class Car
   ...
end

When I run the test, ruby is telling me that "InvalidColorEntry" is an undefined method. I have even tried to include the exception class definition in the test file even though I do not want to do that.

How can I make my test file aware of the custom exception definition? It obviously sees the car.rb file because it is able to call Car.set_color

Thanks!

+1  A: 

It thinks InvalidColorEntry is supposed to be a method because you do InvalidColorEntry "Exception not raised for invalid color", which it parses as InvalidColorEntry("Exception not raised for invalid color").

I think you're just missing a comma after InvalidColorEntry.

sepp2k