난수가 20 미만인 경우에만 이러한 테스트가 통과한다는 문제가 있습니다. 테스트에서이 문제를 어떻게 설명합니까?rspec 테스트에서 임의의 숫자를 어떻게 고려해야합니까?
내 테스트 :
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
또는 어쨌든 궁극적으로 더 유연 난수 생성기의 구현을 제공합니다. –