I've looked at other examples of tests, but most other examples don't necessarily have a variable that is equal to 'gets.chomp.downcase' and it's making it difficult for me to test.
The rest is for a chess game but I'm trying to make it so if you type in "new" in the introduction, it'll call the method #instructions, which displays the instructions and asks if you're ready to play.
Here's the method #introduction
def introduction
puts " \n"
print " Welcome to chess! "
puts "What would you like to do?"
puts "
* Start a new Game -> Enter 'new'
* Load a saved Game -> Enter 'load'
* Exit -> Enter 'exit'"
input = gets.chomp.downcase
if input == "new"
instructions
elsif input == "load"
load_game
elsif input == "exit"
exit!
else
introduction
end
end
Here's the test that I have for it that keeps displaying the error "Failure/Error: input = gets.chomp.downcase"
"NoMethodError: undefined method `chomp' for nil:NilClass"
describe Game do
describe "#introduction" do
it "starts a new game with input 'new'" do
io = StringIO.new
io.puts "new"
$stdin = io
game = Game.new
game.introduction
allow(game).to receive(:gets).and_return(io.gets)
expect(game).to receive(:instructions)
end
end
end