-2
我有我的班級玩家和我的班級遊戲的紅寶石代碼,我正在打網球卡塔。返回帶有屬性的字符串
class Player
def score
if @player_one.points <3 and @player_two.points<3
"#{@player_one.score} #{@player_two.score}"
elsif @player_one.points == @player_two.points
"#{@player_one.score} iguales"
end
if @player_one.points == 3 and @player_two.points == 3
'deuce'
elsif (@player_one.points == @player_two.points + 1) and (@player_two.points >=3)
"Ventaja #{@player_one.name}"
elsif (@player_one.points >= 4) and (@player_one.points >= (@player_two.points + 2))
"Game #{@player_one.name}"
end
end
end
而且這個測試不能通過,所有已經通過的其他測試都不在這裏。
it 'return 30-iguales when both players have 2 points scored' do
player_one = Player.new
player_two = Player.new
game = TennisGame.new(player_one, player_two)
player_one.wins_point
player_one.wins_point
player_two.wins_point
player_two.wins_point
expect(game.score).to eq("30 iguales")
end
我得到的錯誤是「30 iguales」,但得到了nil
。 我的所有其他測試都已通過,但在此失敗,我無法解決問題。
請在開始時解釋一下你的代碼打算做什麼。大多數讀者不會理解「階級遊戲」和「階級玩家」。 –