【发布时间】:2009-08-11 00:22:08
【问题描述】:
我有这样的事情:
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会发生这种情况吗?它对我来说应该输出“你把狗搞砸了”..