1
我在rspec中測試一些隨機行爲時遇到了一些麻煩。如果一個隨機生成的數字等於10,我有一個類應該改變其中一個類實例變量的方法。無論如何我無法找到正確測試rspec。在rspec中測試簡單隨機行爲的問題
下面是類的代碼
class Airport
DEFAULT_CAPACITY = 20
attr_reader :landed_planes, :capacity
attr_accessor :weather
def initialize(capacity=DEFAULT_CAPACITY,weather = "clear")
@landed_planes = []
@capacity = capacity
@weather = weather
end
def stormy
if rand(10) == 10 then @weather = "stormy" end
end
end
沒有人知道的一種方法,我可以寫測試風雨飄搖的方法?