This note aims at explaining how to test user input in RSpec.
I'm building a Tic-Tac-Toe game in Ruby. Before the game starts, I need to ask the user for name, in what mode (player vs player, player vs computer) he/she wants to play, and for the sign (eg. X or O).
In order to test it, I've stubbed the gets
method.
It means that each time there was a gets.chomp in the code, I've stubbed it in the test in order to pass an user input. This allowed me to fluently run the tests, without the need of passing user input manually.