class Game
def start
@player1 = Player.new("don")
@player2 = Player.new("tum")
end
def player_turn
if @turn.even?
puts "this is #{@player2.name}'s turn"
else
puts "this is #{@player1.name}'s turn"
end
end
end
我认为首先您必须定义实例变量@turn
,以及如何对其进行递增。另外,我建议将Game#start更改为#initialize,下面的测试假定了这一点。然后,您可以检查输出到stdout的内容。
RSpec.describe Game do
describe "#player_turn" do
context 'when the turn is even' do
let(:game) { Game.new }
it "tells you it is player 2's turn" do
expect do
game.player_turn
end.to output("this is tum's turn\n").to_stdout
end
end
end
end