我试图了解在 rspec 中测试 while 循环的最佳方法是什么。
我允许用户输入他/她想玩的游戏类型。
def get_action
gets.strip.downcase
end
def type_of_game
puts "Enter the type of game you would like to play (human v. human, computer v. computer, or human v. computer):"
gametype = get_action
until (gametype == "human v. human" || gametype == "computer v. computer" || gametype == "human v. computer")
puts "Please enter a valid game"
gametype = get_action
end
return gametype
end
Run Code Online (Sandbox Code Playgroud)
目前我在 rspec 中有这个,但它会导致无限循环
require "minitest/spec"
require "minitest/autorun"
describe Game do
before :each do
@game = Game.new
end
it "should prompt to user to enter their gametype again if not human v. human, computer v. computer, or human v. compouter" do
def @game.get_action; "human v. machine" end
expect(@game.type_of_game).to eql("Please enter a valid game")
end
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
| 归档时间: |
|
| 查看次数: |
1780 次 |
| 最近记录: |