小编avn*_*510的帖子

rspec 中的 while 循环

我试图了解在 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 …
Run Code Online (Sandbox Code Playgroud)

ruby rspec

5
推荐指数
0
解决办法
1780
查看次数

标签 统计

rspec ×1

ruby ×1