這裏是一個的給錯誤/ falure方法:RSPEC調用方法錯誤
def draw?(board)
if full?(board) == true && won?(board) == false
return true
else
return false
end
end
的方法做一切應該做的事但這是當我運行RSpec的文件時出現錯誤:
1) ./lib/tic_tac_toe.rb #draw? calls won? and full?
Failure/Error: expect(self).to receive(:won?).with(board)
(#<RSpec::ExampleGroups::LibTicTacToeRb::Draw:0x00000002e300b0>).won?(["X", "O", "X", "O", "X", "X", "O", "X", "O"])
expected: 1 time with arguments: (["X", "O", "X", "O", "X", "X", "O", "X", "O"])
received: 0 times
這裏的RSpec的測試:
describe '#draw?' do
it 'calls won? and full?' do
board = ["X", "O", "X", "O", "X", "X", "O", "X", "O"]
expect(self).to receive(:won?).with(board)
expect(self).to receive(:full?).with(board)
draw?(board)
end
基本上,我讀到:#draw?未能調用#full?並榮獲?
但是當我看着我的#draw?方法,我叫他們!作爲「if」條件的!
所以我在哪裏出錯?
非常感謝幫助!
我目前在學習Ruby。
我忘了短路,謝謝!這是我正在經歷的在線課程的一部分,我不應該觸摸測試,但測試該功能的輸出確實更有意義!雖然Rspec運作良好,但對於我爲一個井字遊戲製作的整體CLI而言,Rspec仍然會引發錯誤。所以我繼續前進。真的很感激這個信息! – Edson