title: How do I write an RSpec test for a Ruby method that contains "gets.chomp"?
body: <h1>Challenge</h1>
  
  <p>Hi!  For the following Ruby method, how might I simulate user input using an RSpec test without rewriting the method?</p>
  
  <pre><code>def capture_name
    puts "What is your name?"
    gets.chomp
  end
  </code></pre>
  
  <p>I've found <a href="https://stackoverflow.com/questions/4609872/rspec-commandline-variable-input">a similar question</a>, but this approach requires creating using a class.  Does RSpec support stubbing for methods not in a class?</p>
  
  <h1>A different works, but I'm forced to rewrite the method</h1>
  
  <p>I can rewrite the method so it has a variable with the default value of "gets.chomp" like this:</p>
  
  <pre><code>def capture_name(user_input = gets.chomp)
    puts "What is your name?"
    user_input
  end
  </code></pre>
  
  <p>Now I can write an RSpec test like this:</p>
  
  <pre><code>describe "Capture name" do
    let(:user_input) { "James T. Kirk" }
  
    it "should be 'James T. Kirk'" do
      capture_name(user_input).should == "James T. Kirk"
    end
  end
  </code></pre>