title: Rspec - Stubbing gets.chomp out of the constructor
body: <p>I'm writing a Mastermind game in Ruby and in the constructor of the class 'Game' I want to use gets.chomp to ask the user for its name. Pretty easy, but where I run into trouble is when testing this class in RSpec, but I can't seem to properly stub out 'gets' and 'puts', because they are in the constructor not a regular method.</p>
  
  <pre><code>class Game
    def initialize
      puts "Please enter your name:"
      @player = Player.new(gets.chomp)
    end
  end
  
  describe Game do
    Game.stub(:gets).and_return("Create Code AI")
    Game.stub(:puts)
    subject(:game) { Game.new }
  
    describe "#new" do
      its("player.name") { eql("Create Code AI") }
    end
  end
  
  class Player
    attr_reader :name
  
    def initialize(name)
      @name = name
    end
  end
  </code></pre>
  
  <p>I've also tried putting the stubs into 'before' and 'let' blocks amongst other things, but nothing seems to work. Any help is appreciated!</p>