Test gets with rspec

Hi body, i just want to test gets with rspec, I see something on
stackoverflow but doest work to me
I would like to know too
When i run the tests a method that should be tested has called gets
method and it run when i test, so i have to push ENTER to pass the gets
method ever time i test the app.
Someone know how can i solve this?
Thanks everone.

Hallo Body? Who? Some Body?

Anyway, if you would like help, then you really need to include your
program and the error message.

Sounds also, like a look at the documentation for gets would help:
http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-gets

Ruby’s irb is also a useful tool to try things out with, especially when
you just want to see what a core method or class does.

$ irb
irb(main):001:0> gets
this that the other
=> “this that the other\n”
irb(main):002:0

gets _get_s a _s_tring, mostly from the user. The input string is
terminated by pressing the return key. puts _put_s a _s_tring, mostly to
the user.

You probably don’t need to test gets, but you may want to test what your
program is doing to the input from gets, which is a good reason to
separate this part of your program into two methods, the first gets the
user input, the second method takes a string argument and does something
to it. This second function can be tested.

RSpec.describe TalkBack do
it ‘says everything backwards’ do
expect(talk(‘stressed’)).to eql(‘desserts’)
end
end

class TalkBack
def getStringFromUser
talk(gets.chomp)
end

def talk(user_said)
“#{user_said.reversed}”
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs