title: Rspec: mock a nested/dependency injected object
body: <p>I am having trouble mocking an injected object. For example:</p>
  
  <pre><code>class Foo
    def initialize(bar = Bar.new)
      @bar = bar
    end
  
    def run
      @bar.do_something_cool
    end
  end
  
  # Rspec
  describe Foo do
    it "should do something cool" do
      mock_bar = mock("bar")
      mock_bar.stub(:do_something_cool).and_return(nil)
  
      real_foo = Foo.new(mock_bar)
      real_foo.run
  
      mock_bar.should_receive(:do_something_cool).once
    end
  end
  </code></pre>
  
  <p>If I run this, the spec fails because it says the "do_something_cool" is never called.</p>
  
  <pre><code> expected: 1 time
   received: 0 times
  </code></pre>
  
  <p>However, if I do not stub "do_something_cool", I get the following error</p>
  
  <pre><code>Mock "bar" received unexpected message :do_something_cool with (no args)
  </code></pre>
  
  <p>Any ideas?</p>