rspec/rspec-mocks — pull request #387 by JonRowe (2013-07-30 11:06:06+00:00)
Title: and_return broken on implicit (self) receiver stubs

RSpec 2.13 supported implicit receivers inside describes. For example, instead of doing `obj.stub!(...)`, you could do `self.stub!(...)` (or just `stub!(...)`), where self is the context of the `it` block. This was not a common usage, but it is extremely useful for testing modules with private features. You could `include Foo` into your context and use it from the spec. This no longer works in 2.14.

Minimal reproduction:

```ruby
require 'rspec'

describe 'implicit mocks' do
it 'accepts and_return on an implicit mock' do
stub!(:foo).and_return('bar')
expect(foo).to eq('bar')
end
end
```

Output:

```
~/spec$ rspec foo_spec.rb
F

Failures:

1) implicit mocks accepts and_return on an implicit mock
Failure/Error: stub!(:foo).and_return('bar')
Stub :foo received unexpected message :and_return with ("bar")
# ./foo_spec.rb:5:in `block (2 levels) in '
```

A more complete usage scenario might be:

```ruby
require 'rspec'

module Foo
private # these methods are not callable from outside
def foo; bar end
def bar; 0 end
end

describe Foo do
include Foo

describe '#foo' do
it 'returns the result of #bar' do
stub!(:bar).and_return(42)
expect(foo).to eq(42)
end
end
end
```

If this will not be supported in 3.x, are there any suggestions on how to not rely on implicit receivers for these tests?