# Simple way to supply test input for gets?

**URL:** <https://www.ruby-forum.com/t/simple-way-to-supply-test-input-for-gets/208355>\
**Category:** RSpec\
**Created:** [June 16, 2011, 12:13am UTC](https://www.ruby-forum.com/t/simple-way-to-supply-test-input-for-gets/208355 "2011-06-16T00:13:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 16, 2011, 12:13am UTC](https://www.ruby-forum.com/t/simple-way-to-supply-test-input-for-gets/208355/1 "2011-06-16T00:13:30Z")

</div>

Hi there,  
I’m pretty new to rspec and have not been able to figure out how to run  
a basic test that allows me to substitute test input for real user input  
collected by ‘gets.’ I have a command line program that asks the user  
for a CSV file name and then converts that to a database. Now, I know  
this works already, but I’d like to make a test for it and other similar  
operations that require user input.

Here’s the code in it’s most basic form:  
puts “What is the name of your CSV file?”  
user\_csv = gets.chomp  
original\_dataset = Statsample::CSV.read(’./’ + user\_csv)

What I’d like to be able to do is have rspec automatically substitute  
‘test.csv’ for whatever would normally be entered by the user. This test  
I put together below doesn’t pass obviously, because there is no  
substituted value for that user input.

Test in need of fixing:  
class DatasetGetter  
describe “#get\_original\_dataset” do  
let(:dataset\_getter) { DatasetGetter.new }

```
it 'should produce a Statsample Dataset object' do
dataset_getter.original_dataset.class.should ==

```

‘Statsample::Dataset’  
end  
end  
end

Is there a relatively easy way to do this? Thanks for the help!
