我有这样的事情:无法捕捉异常,在Ruby中
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
但由于某些原因,我的测试是提高异常并停止执行,而不是抓住它和输出的“你搞砸了的狗。”任何想法为什么发生这种情况,以及如何解决它?
谢谢!
请问如果你'TestCase的外c.make_car'出现这种情况?它输出“你搞砸了这只狗”,因为它对我来说应该是这样.. – dbr 2009-08-11 01:34:37