これらのテストは、乱数が 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