I'm trying to understand what the best way to test a while loop in rspec would be.
I allow the user to enter the type of game he/she would like to play.
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
Currently I have this in rspec, but it results in an infinite loop
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
Thanks for your help