Posted almost 6 years ago. Visible to the public.
Stubbing terminal user input in RSpec
Reading user input in console applications is usually done using Kernel#gets
. Stubbing that can be a bit hairy.
When your code expects user input, you can not say Kernel.stub(gets: 'user input')
. This will have no effect because of reasons.
Instead, you need to know which class will call gets
. For example:
Copydescribed_class.any_instance.stub(gets: 'user input')
If you do not know where gets
is called, you can try something like this:
CopyObject.any_instance.stub(gets: 'user input')
Any instance of an object should eventually hit that stub.
Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).