Skip to content

Instantly share code, notes, and snippets.

View BShowen's full-sized avatar
🦑

Bradley Showen BShowen

🦑
  • Self Employed
  • Orlando, FL
View GitHub Profile
@Kotauror
Kotauror / user_input_test.md
Created March 24, 2018 12:38
Testing user input in RSpec

Testing user command line input in RSpec.

This note aims at explaining how to test user input in RSpec.

Background

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.

Examples of code