Я пытаюсь понять, какой лучший способ проверить цикл while в rspec.Пока петли в rspec
Я разрешаю пользователю вводить тип игры, в которую он/она хотел бы играть.
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
В настоящее время у меня есть это в 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
Спасибо за вашу помощь