0
通常、1から10までの乱数を返すときにメソッドが特定の値を返すと仮定するrspecテストを作成しようとしているここでメソッドがRspecで特定の値を返すようにする(そうでなければランダムになる)
は私のlibディレクトリ内のコードです:
def take_off(plane)
fail "Bad weather today. Cannot take off." if stormy_weather? > 8
plane.take_off_plane
planes.delete(plane)
end
def stormy_weather?
rand(10)
end
そして、ここでは、RSpecの中に私のテストで:
it 'raises an error when weather is stormy' do
plane = double(:plane)
stormy_weather = 9
allow(plane).to receive(:take_off_plane)
expect{ subject.take_off(plane) }.to raise_error("Bad weather today. Cannot take off.")
end
ができます誰にも事前にありがとうございます!
はいああ!私は実際にそれを 'allow(subject).to receive(:stormy_weather?)にしなければなりませんでした。and_return(9)' – Freddy
@Freddy –