I am trying to create a method that takes in a user input. It turns that user input into an integer, it then subtracts one from the user input. It also returns -1 if the user input is not a number. However the tests throws an error.
describe '#input_to_index' do
it 'converts a user_input to an integer' do
user_input = "1"
expect(input_to_index(user_input)).to be_a(Fixnum)
end
it 'subtracts 1 from the user_input' do
user_input = "6"
expect(input_to_index(user_input)).to be(5)
end
it 'returns -1 for strings without integers' do
user_input = "invalid"
expect(input_to_index(user_input)).to be(-1)
end
end
Here is my method:
def input_to_index(user_input)
user_input = user_input.to_i
user_input = user_input - 1
return -1 if !user_input.is_a? Numeric
end