rspec/rspec-mocks — pull request #239 by jshraibman-mdsol (2013-03-15 01:27:18+00:00)
Title: Make sure the Proxy being returned is actually for this object.

I was getting failures in my helper specs (seems like the same problem mentioned [here](http://stackoverflow.com/questions/10537932/unable-to-stub-helper-method-with-rspec)). I couldn't call a mocked method on my object right after defining it:

```ruby
helper_obj = helper
helper_obj.stub(:blahblah).and_return( 'blah')
helper_obj.blahblah.should == 'blah'
```

I eventually traced the issue:

* ```helper``` is really an alias of ```view```
* When view is called ActionView::TestCase::TestController passes all its instance variables, including @mock_proxy, into the new view
* Calls to ```stub``` were adding stubs to the proxy for the controller, not the object I was calling stub on.

I tried a fancier solution than this that hid the proxy in the eigenclass of the eigenclass but that resulted in a spec failure:
```
1) RSpec::Mocks::Serialization marshals the same with and without stubbing
Failure/Error: after = Marshal.dump(serializable_object)
TypeError:
singleton can't be dumped
# ./spec/rspec/mocks/serialization_spec.rb:99:in `block (2 levels) in '
```

This solution seems a little ugly but it works.

rake passes with these changes:

```
Finished in 0.34682 seconds
691 examples, 0 failures, 2 pending

47 scenarios (47 passed)
151 steps (151 passed)
0m34.032s
```
I considered adding a test case for this but it seemed a little weird to me to be copying the proxy from one object to another in a spec. Do you think I should?