I have something like this:
class Vehicle
def self.set_color(input)
if %w{blue red green}.include?(input)
input
else
raise "Bad color"
end
end
end
class Car < Vehicle
def make_car
begin
my_color = Vehicle.set_color("orange")
rescue
puts "you screwed the pooch"
end
end
end
class CarTest < Test::Unit::TestCase
def test_number_one
c = Car.new
c.make_car
end
end
But for some reason, my test is raising the exception and stopping execution instead of catching it and outputting “you screwed the pooch.” Any idea why this is happening and how to fix it?
Thanks!
rescue without an argument is not a “catch-all” for exceptions.
If you just issue a “rescue” it will only rescue a StandardError exception (which will catch a RuntimeError < StandardError) , but not an Exception.
If you really want to catch everything, you should do a