我有一个问题,这些测试只有在随机数低于 20 时才能通过,我如何在测试中解决这个问题?
我的测试:
it 'a plane cannot take off when there is a storm brewing' do
airport = Airport.new [plane]
expect(lambda { airport.plane_take_off(plane) }).to raise_error(RuntimeError)
end
it 'a plane cannot land in the middle of a storm' do
airport = Airport.new []
expect(lambda { airport.plane_land(plane) }).to raise_error(RuntimeError)
end
我的代码摘录:
def weather_rand
rand(100)
end
def plane_land plane
raise "Too Stormy!" if weather_ran <= 20
permission_to_land plane
end
def permission_to_land plane
raise "Airport is full" if full?
@planes << plane
plane.land!
end
def plane_take_off plane
raise "Too Stormy!" if weather_ran <= 20
permission_to_take_off plane
end
def permission_to_take_off plane
plane_taking_off = @planes.delete_if {|taking_off| taking_off == plane }
plane.take_off!
end